On Wed, Mar 16, 2011 at 11:33:37AM -0700, pbg wrote:

>        Im a beginner to git . I did a git add <directory> . It added
> all the files in the directory some of them are .o and generated files
> so i did not want to commit . so i did a git revert . After that i see
> that git revert removed all  my files in directory !!!! .. i did not
> expect that . How to restore my files?  .It removed all the files i
> have worked on for some time. I had to rewrite all the files again. I
> think this is not a good behaviour of git .. Is this correct ?
It's better phrased that it's not a behaviour of Git you expected.
I mean that if Git would refuse to delete the files added by the
commit being reverted, that could raise some eyebrows, too.

> is there any way i can restore my files ?
Reverting a commit does not rewrite history but rather it's appending a
new record to the chain of commit: git-revert records a new commit which
undoes the changes introduced by the reverted commit. Hence, the
original commit is still present in the history record and, which might
or might not be more important, the commit immediately preceding the new
one introduced by git-revert's action is also present.
So, to undo what git-revert did just immediately perform
$ git reset --hard HEAD^
which just forgets the tip commit (that one recorded by git-revert).
Note that obviously this only works if you did not commit anything
after git-revert. Otherwise you would either use rebasing to remove the
commit recorded by git-revert or just revert it.

In other words, please read the git-revert man page and try to fully
understand what git-revert does. Then the ways to undo its changes will
be clear (provided you have read about undoing changes in Git which is

For the future, note that git-revert supports the --no-commit command
line option which allows you to edit the index formed by the git-revert
action before committing its state. So you could use it to unstage the
deletion of "correct" files and then commit.

You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
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