0

I have a new repository. I added some files (a,b,c) via

git add .
git commit -m "x"

I realized file c was unnecessary so I looked for the last commit via

git log

with the commit id at hand I did

git revert commit-id

it started deleting all files removing file a b c

How can I restore them? I looked at the log and only the original commit x is in there.

I tried

git checkout HEAD^^ -- .

as per How do I "un-revert" a reverted Git commit?

but I get "Invalid reference HEAD^^"

any ideas?

Koenig Lear
  • 2,366
  • 1
  • 14
  • 29

2 Answers2

2
  1. Get the commit hash of the initial commit where you added the files by doing a git reflog (this is essentially a log of all of the recent HEADs of your branch - very useful for scenarios like this).
  2. If you want to permanently go back to this commit and completely 'undo' your revert then do a git reset --hard <commit-id> replacing the hash with the hash of the initial commit where you added the files. If you want to temporarily go back to this commit then do a git checkout <commit-id>.

Further reading on git reflog: http://gitready.com/intermediate/2009/02/09/reflog-your-safety-net.html

simon-pearson
  • 1,601
  • 8
  • 10
0

Have you tried

// It will reset your commit back to previous if its 2 commits back then use head~2 etc.
git reset head~1
Mike
  • 1,313
  • 12
  • 21
  • I get ambiguous argument head~1 unknown revision or path in the working tree. There's only 1 commit in the log. – Koenig Lear Mar 29 '20 at 12:05