简体   繁体   中英

recovering deleted files git after revert

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 abc

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?

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
  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM