As long as you don't delete your local repository, you can always get the 
old code back out again. Whatever you do, do NOT delete your local 

When you do a commit or a merge, it first and foremost only happens in your 
own local repository. This means that you can remove any accidental commits 
like this by resetting your local branch:

git commit -am "Lots of horrible stuff"
#oooops, better undo that
git reset --hard HEAD~1

reset --hard will move the entire state of your repo to the target version, 
which in the case above means the second-last commit (HEAD minus one 

This also works for accidental merges:

git merge horrible-branch
#ooops, better undo that merge
git reset --hard HEAD~1

If you need to reach deeper into the history to find the state you want to 
revert to, git reflog is what you need:

git reflog

This will output a log-file with a chronology of all the operations you 
have done locally (at least the last 30 days), and a reference to the code 
as it was after each operation. Just pick the point in time where you had 
the state you want, and use reset on this:

git reset --hard a01bd6a # where a01bd6a is a reference that I copied out 
of the reflog

NOTE: If you have already pushed the deletion of the code out to your team, 
or to a shared repository, you cannot reset the code like this. Then you 
need to turn to use revert like you did already, and then push out the 
revert commit.

If your team-mates are OK with it, and are ready to reset their own local 
repositories correspondingly, you can (but make sure everyone is OK with 
this before you do, or there will be trouble) push the correct state of the 
repository with the --force option. This will rewrite history in the shared 
repository that you are pushing to (this is usually a really bad idea to 

If you have further questions, please respond with a step-by-step 
explanations of the exact git commands you performed. It's not so easy to 
interpret what has happened in your case here.

On Monday, July 2, 2012 3:58:25 PM UTC+2, git-guy wrote:
> hi guys i dont knwo what happen
> but i make one merge and after um git push
> and deleted 3000 files in my project.
> how i can go back this merge?
> i tried git revert numbercommit    but not working?
> some help?

You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To view this discussion on the web visit 
To post to this group, send email to git-users@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to