开发者

Git undo - make sure that local files are the same as a previous commit on Git

Please help I'm new to Git - Something has gone seriously wrong in my application and I want to restore a previous commit - but nothing is working - No matter what I开发者_开发技巧 do I still see the later files on my local hard drive. How can I restore to a previous commit and make sure that this is what I have to work with on my local machine?


If you haven't pushed, try git reset --hard HEAD.

Otherwise git revert HEAD will create a commit exactly the opposite of what you did on your latest commit.

You can also specify a commit hash instead of HEAD to undo a specific commit.


Resetting back to a last commit:

$ git reset --hard HEAD

Be aware that all uncommitted changes will be discarded. This will revert all files back to the last committed state. HEAD can also be edited to match a sha1 hash of the commit to revert to a specific commit.

For more info on resetting, read this: http://progit.org/2011/07/11/reset.html


The first thing is that you can temporary unapply local changes with git stash. You can get these changes back with git stash apply.

When the problem is not in your local changes, you can check out older revisions with git checkout <commit-id>, where commit-id is either the hash of the commit, a branch name or a special reference like HEAD^. You are on a detached head afterwards, which means if you want to do any code changes on the checked out revision you must create a new branch from this revision (git checkout -b <new-branchname>).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜