简体   繁体   English

Visual Studio 代码 Git“还原提交(通过终端)”删除了我的文件

[英]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).我的 Git 经验非常有限,在 Visual Studio 代码上:我对我的存储库做了很多更改,然后我提交了它们(没有推送)。

There is a visual studio extension called GitLens: I right click my commit and clicked "Revert Commit (via terminal)"有一个名为 GitLens 的 Visual Studio 扩展:我右键单击我的提交并单击“还原提交(通过终端)”

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"?根据这个问题有没有办法撤销“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)我能够从 Visual Studio 代码和 gitlens 扩展中恢复提交版本,即使在提交没有出现在列表中之后(在撤销提交之后)

On gitlens extension there is a tab for search commits, you can search the commit by its ID.在 gitlens 扩展上有一个用于搜索提交的选项卡,您可以通过其 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.只要文件仍然在您的编辑器(如 VSCODE)中打开,您就可以撤消(command-Z/ctrl-Z)并返回到 git reset 之前的状态。 Of course the trick only works if you keep your files open当然,这个技巧只有在你保持文件打开的情况下才有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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