How do I rollback to a specific git commit

久未见 提交于 2019-12-10 23:33:51

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!