Git Learning (iv)----version jump

Source: Internet
Author: User

git log, git reflog, git reset

Git version jump:

To implement a version jump, you need to understand the git version of the tag, that is, through this unique tag to locate a version, that is, the commit ID.

This commit ID is a very long string, because it is computed by SHA-1. (This string is quite similar to some of the magnetic links in your hard drive, hey!) Because Git is distributed, so everyone has the complete code on the computer, if you update someone else's file on this machine, he commits the commit ID is simple self-increment number (...), it is possible to conflict with the commit ID on your local machine, Then it's not going to work, ha. (To ask "SHA-1 can do not repeat?" "Children's shoes, you go to see the principle of SHA-1 , it is best to the principle of digital signature also read, are very interesting ha." Besides, if this SHA-1 code is easy to produce the same words, when you use those magnetic links, it is not easy to make the wrong file. )

To get started, let's first find out the commit ID for all versions, enter:git log (show all commit logs)


This looks inconvenient, input:git log--pretty=oneline


The long yellow string in front is the commit ID.

version jump: git reset

Git reset directly with the commit ID can be implemented version jump (commit ID not all write, write to 7 bit on it)

However, when you open the Test2.txt file, you find that the file does not change at all. (a face is crazy)

This time to believe that the program, no error indicates that the operation is not wrong, check git status: Git status

This time found that the original GIT internal record has been rolled back to the specified date of the record, but the file is not rolled back, the file will be modified as the file will be different from the "record" to save the content.

If you want the contents of the file to also be rolled back: git reset--hard plus commit ID

View operations git reflog

If, after a rollback, it is not possible to find this version, or to return just that version, but git log does not show just that version of the commit ID.

This time will be used: Git reflog

(I did a lot of reset operations, mainly looking at the red Arrow records on the line.) )

This time want to go back to add4, input: git reset b1ca470

Git log view version information

Git reflog View operation information



Git Learning (iv)----version jump

Related Article

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.