简体   繁体   中英

visual studio code Git "revert commit (via terminal)" deleted my files

My Git experience is very limited, On visual studio code: I did a lot of changes to my repository and then I committed them (no push).

There is a visual studio extension called GitLens: I right click my commit and clicked "Revert Commit (via terminal)"

This ran the following command

-> git revert -e bdb001d91a63c1e898da18c54916a8834579d20b

which deleted the files and reset the files to the version before commit. I don't want this to happen

Is there a way to restore the commit that I have reverted back? Thanks

according to this question Is there any way to undo the effects of "git revert head"?

I tried

-->git reset --hard HEAD^
--> HEAD is now at 1fd24c8 fix folder

also

--> git revert --abort
--> error: no cherry-pick or revert in progress
--> fatal: revert failed

--> git log -5
commit 1fd24c8c4c4ef95f954e5b6af94ad0dedfbbf5f0 (HEAD -> master, origin/master)
Author: xxxxxxxxxxxxx
Date:   Thu Oct 25 23:24:13 2018 +0200
    fix folder

commit ec426d893f254e88f488be8bb3e2de781dfbc446
Author: xxxxxxxxxx
Date:   Thu Oct 25 23:19:26 2018 +0200
    firstcommit repname

I was able to restore the commit version from the visual studio code and gitlens extension, even after commit does not appear on list (after undo commit)

On gitlens extension there is a tab for search commits, you can search the commit by its ID.

Then Right click the commit and click on "checkout commit".

Not the solution but a bit of a trick here. As long the files are still open in your editor (like VSCODE) you could undo (command-Z/ctrl-Z) and go back to the state before the git reset. Of course the trick only works if you keep your files open

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