【问题标题】:visual studio code Git "revert commit (via terminal)" deleted my filesVisual Studio 代码 Git“还原提交(通过终端)”删除了我的文件
【发布时间】:2019-05-31 08:39:15
【问题描述】:

我的 Git 经验非常有限,关于 Visual Studio 代码: 我对我的存储库做了很多更改,然后 我承诺了他们(没有推动)。

有一个名为 GitLens 的视觉工作室扩展: 我右键单击我的提交并单击“Revert Commit (via terminal)”

这运行了以下命令

-> git revert -e bdb001d91a63c1e898da18c54916a8834579d20b

删除文件并将文件重置为提交前的版本。我不希望这种情况发生

有没有办法恢复我已恢复的提交? 谢谢

根据这个问题Is there any way to undo the effects of "git revert head"?

我试过了

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

还有

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

【问题讨论】:

  • 您是否尝试将樱桃选择直接应用于您删除的提交?代码将是git cherry-pick <commit code>
  • 不,我主要通过 Visual Studio 代码设法恢复它们

标签: git visual-studio-code git-revert


【解决方案1】:

我能够从 Visual Studio 代码和 gitlens 扩展恢复提交版本,即使提交未出现在列表中(撤消提交后)

在 gitlens 扩展上有一个用于搜索提交的选项卡,您可以通过其 ID 搜索提交。

然后右击提交,点击“checkout commit”。

【讨论】:

  • 只想感谢您发布您如何解决这个问题作为答案,而不是放弃问题或评论,“没关系,想通了”。
【解决方案2】:

这里不是解决方案,而是一个技巧。只要文件仍然在您的编辑器中打开(如 VSCODE),您就可以撤消(command-Z/ctrl-Z)并返回到 git 重置之前的状态。当然,这个技巧只有在你保持文件打开的情况下才有效

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-26
    • 2011-09-06
    • 2011-01-29
    • 2019-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多