A little summary of Git and GitHub (II.)

Source: Internet
Author: User

Continue the local git usage process for the previous article

4, after tracking a file, Git can record its every change (that is, version), and then fallback or forward to a version as needed. When you make a change to a file, the most important thing is to commit the change in time and enter Git commit

(Note add before each commit.) Appears after Git commit)

(This has been modified because the GIT default editor is the Nano, and the personal feel is not good, so with git config--global core.editor vim command to change the default editor to Vim)

The first line is to enter a description or tag for this commit and so on, so that when someone review quickly know what you did in this submission, I wrote a random:


Then enter: Wq exit, as follows:


The status of this commit is displayed.

(1) If you have to open vim every time trouble, you can directly put the submission instructions behind the-m parameter, as follows:


(2) Further, if you have to add trouble every time you modify, you can include the-a parameter, as follows:


This parameter will commit all changes from the last commit to the current one at a time, and no need to add any more.

(3) If the last commit information is wrong, then the--amend parameter gives you a chance to change the error:

(The original submission information is fourth)

(Input git commit--amend will open vim, I change the information into Fourth_new, save exit)

(The new submission is fourth_new)

Note that this only modifies the commit information and cannot modify the submission itself.


5, review the commit history, use the git log command to view all the history submissions, it uses the less command to list all the submission instructions, such as:


You can see that the order of the display is reversed, starting with the last commit, the more "old" the lower the submission. If you want to see only the last n commits, not all of them, you can add a parameter as follows:

(Only the last two submissions are listed)

Just git log information is still the pattern Tucson broken, want to further see details, you can use the-P option, as follows:


There is also a--stat option that is used to count information, mainly the number of rows added and removed, and the last list of all additions and deletions.
Number of subtotal:


Git log also has a lot of options, their magical self-study it slowly.


6. Fallback version: git reset command. This is a very important command, for me, it is my git regret medicine, regret medicine Ah Pro ~

(1) Previously said git checkout file command, that is, undo the changes made to the files, but there is a premise that there is no git add this modification, or git checkout is not working, as follows:


(git checkout code.c doesn't work )

To make this command work, first undo the Add command, as given in the status prompt:


Then checkout works, in other words, git checkout only works on those unmodified changes:


(2) to get the file back to the last commit, for example, we see the last two commits:


Now, CODE.C is the way fourth_new commits, so how do you make it look like third commits? As follows:


Haha, success! It is important to note that, head^, the HEAD here refers to the latest commit, plus a ^ that represents the last commit, two representations on the last commit ... How many can it add? Well, I don't know, but if you add too much, you can't count it, right? So, if you want to fall back to a very former version, you can actually directly replace the head with the long ID behind the commit, as follows:

(This is the last three commits, the following demo directly back to the second version)

Finish ~ ~ But by--hard you also see this method is very violent, second after the several submissions were abandoned.


A little summary of Git and GitHub (II.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.