Three minutes to learn about git (4) Emergency Rescue

Source: Internet
Author: User

Suppose you are not careful about git reset -- hard head ^

Then this commit is not in another git repository. What should I do? Is this change lost?


Of course not. Git retains the reference log for every history.

For example:

$ Git commit-a-m "hongchangfirst commit"

Now you can view the history of git. You can see two commits:
$ Git log
* D1f3fg5 (Head, Master) hongchangfirst commit



Now let's reset the status of the first submission:
$ Git reset -- hard head ^

This submission failed, but we still have a way to restore it, because a reflog will record the history of all headers. For example:

$ Git reflog
A6h8jha [email protected] {0}: Reset:
D1f3fg5 [email protected] {1}: commit: hongchangfirst commit



Therefore, to retrieve the lost commit, we only need:
$ Git reset -- hard d1f3fg5


Let's take a look at the GIT record:
$ Git log
* D1f3fg5 (Head, Master) hongchangfirst commit

Okay, that's it.

Original article: http://blog.csdn.net/hongchangfirst/article/details/30458313

Author: hongchangfirst

Hongchangfirst home: http://blog.csdn.net/hongchangfirst


Three minutes to learn about git (4) Emergency Rescue

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.