Restore my application with git
I want to restore my application to an old commit I made.
I make commits like this:
git commit -m "blah"
When I press "git lo开发者_StackOverflow中文版g" I see all of the commits I made.
How can I restore my application with git?
EDIT:
I did git push (to heroku) , and it said:
error: failed to push some refs to 'git@heroku.com:asfalt.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
It depends - do you want to temporarily move back to an old commit, or do you want to permanently throw away everything after an old commit?
For a temporary move:
git checkout <old commit SHA>
(Note: this will make it so that you are not on any particular branch. If you decide that you want to make commits after this, you'll need to create a branch first.)
To throw away everything after a commit:
git reset --hard <old commit SHA>
When you do a git log you'll see the commits you've made with a sha, for example:
commit 7df7855f2f74007c1d0359f7218be446dd7633e8
Use the sha to do a revert on the changes that you want to roll back. For example,
git revert 7df7855f2f74007c1d0359f7218be446dd7633e8
Use git log
to find the SHA1 hash of the commit you want to revert to (it looks like 9fcf42cb3dcc78e8c62ee1714ee27d42f1275384
), and use :
git checkout 9fcf42cb3dcc78e8c62ee1714ee27d42f1275384
This will detach your HEAD, so be careful if you make commits on top of this one (use git branch -b newbranch
after checkout to avoid this).
精彩评论