开发者

How to undo a Git rollback

I wanted to rollback to the last commit after making a massive error, but I managed to rollback a l开发者_C百科ittle too fair. The commit I wanted to reassert doesn't appear when I enter 'git log' in bash (I suppose because it's no longer in the history). Is there any way I can recover the last commit by date?

I'm also using eGit in eclipse for the same project if that makes things easier. Thanks.


If you are ok with command line, go to you repo, do a git reflog and get the commit which you want to "rollback" to and do a git reset --hard <commit>

You would also be able to do git reset --hard HEAD@{1} and then come back to egit and rollback to the desired commit.


I find that generally it's better to make your changes forward in time rather than backward.

Git's approach is to "revert" the commit. When you revert a commit, you check out into your working directory the inverse of the commit in question. Then you add and commit that, and you've just made a NEW commit, that commits the "undoing" of the commit you're reverting, AND it leaves a record in history that such a thing happened, so if you want to undo your undoing, it's easy to do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜