问题
I have rolled back already using this command git reset --hard HEAD^
to some previous commit, all I want to do is rollforward I know this isn't the correct term to what would be my commit that I did latest. Whats happening is a bunch of files were deleted when I used that command and now I don't know how to get back. I am using github is there a way to just pull down from github and overwrite the current directory?
回答1:
Looking at your question, the commit you want to retrieve is the current one on the master
branch of the GitHub repo, you have to do the following
git reset --hard origin/master
WARNING this will erase all uncommitted modifications that you could have made since you rolled back on HEAD^
.
Before, you might want to do
git fetch origin
To make sure you've got the latest changes from the GitHub repo.
回答2:
Take a look at git reflog
. Among its output you should find the commit you want to reset to. Then git reset --hard
to it and you're back where you were before your first reset
.
git reflog
is especially useful if you really screw your local repository up and don't have a remote repository you can use to pull commits from. It should work fine as long as you haven't called git prune
to get rid of old commits or git reflog expire
to clean the reflog.
来源:https://stackoverflow.com/questions/14703095/how-do-i-rollback-to-a-specific-git-commit