How to version fallback for git tutorials

Source: Internet
Author: User

First, preface

In the previous section, we have learned how to create a repository, how to submit a file to a repository, how to view a record of a recently submitted file, so what if we want to fallback the version now?

Second, step

① now continues to modify the Readme.txt file, adding a row to the content of 33333333. Continue to execute the command as follows:

Git tutorials How to version fallback photos-1

② to the Readme.txt file made three changes, now want to see the history, how to check it? We can now use the command git log as follows:

Git tutorials How to version fallback photos-3

The git log command displays logs from the most recent to the farthest, and we can see the last three commits, the most recent being an increase of 33333333. The last time you added content 22222222, the first time by default is 11111111. If too much information is displayed, We can use the command git log–pretty=oneline demo as follows:

Git tutorials How to version fallback photos-5

③ now I want to use the version fallback operation, I want to fallback the current version to the previous version, what command to use? You can use the following 2 kinds of commands, the first is: Git reset–hard head^ Then if you want to fall back to the first version just change head^ to head^^ and so on. If you want to fall back to the first 100 versions, using the above method is certainly inconvenient, we can use the following simple command operation: Git Reset–hard head~100. The Readme.txt content before fallback is as follows:

Git tutorials How to version fallback photos-7

If you want to fallback to the previous version of the command, do the following:

Git tutorials How to version fallback photos-9

Check out the following Readme.txt content: View by command cat Readme.txt

Git tutorials How to version fallback photos-11

As you can see, the content has been rolled back to the previous version. We can continue to use git log to view the following history information, as follows:

Git tutorials How to version fallback photos-13

We saw an increase of 33333333 content that we didn't see, but now I want to back to the latest version, such as: How to recover 33333333 of the content? We can rollback by version number using the command method as follows: Git reset–hard version number

But now, if I've already turned off the command line or the version number of 3333333, I don't know. How do you know the version number that adds 33333333 content? The version number can be obtained from the following command: The Git reflog demo is as follows:

Git tutorials How to version fallback photos-15

As we can see from the above display, the version number of the added content 33333333 is F676eae. We can use the command git reset–hard F676eae to recover. The demo is as follows:

Git tutorials How to version fallback photos-17

You can see that you are now back to the latest version.

At this point, we have finished introducing how the Git tutorial version fallback.

Original address: http://www.marsitman.com/git/git-back-respository.html (EXT)

How to version fallback for git tutorials

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.