Can we recover deleted commits?
This question already has an answer here:
To get back to that commit you can use the reflog to look up it's ref.
Reference logs, or "reflogs", record when the tips of branches and other references were updated in the local repository.
Run this command:
git reflog
Scan the first few entries, and find the commit that was lost. Keep track of the identifier to that commit (you can use either the 1st or 2nd columns). Let's call the identifier "ID".
If you have not made any extra work since you did the reset --hard you can do:
git reset --hard ID
git push -f origin master
If you have made other work since the reset, you could cherry-pick if back onto your branch like this:
git cherry-pick ID
git push origin master
Yes, You can find your commit in reflog
use:
git reflog
to display all commits which are/were created in your repository - after this you should checkout to removed commit by checkout command
git checkout <your commit-SHA>
or cherry-pick it by:
git cherry-pick <your commit-SHA>
Try git reflog
, aka Reference logs, it allows you to go back to history in your local repo.
https://git-scm.com/docs/git-reflog
链接地址: http://www.djcxy.com/p/3962.html上一篇: 如何撤消'git fetch'
下一篇: 我们可以恢复已删除的提交吗?