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