如何在 Visual Studio 2019 中使用 git 集线器恢复已删除的文件

How do I recover deleted files using git hub in Visual Studio 2019

我在 Visual Studio 2019 年一直在使用 GIT。我不小心删除了几个文件并提交了删除。我怎样才能恢复这些文件?

我可以通过 Visual Studio 查看历史记录并找到我删除这些文件的提交。我尝试了还原、重置 - 保留更改和重置 - 删除更改​​。我的文件没有回来。

我需要做什么才能恢复这些文件?

找到删除文件的提交并将其恢复,然后提交恢复!

在 shell 中,这将是 git log 查看提交日志,然后是 git revert aaaaaa,其中 aaaaaa 是有问题的提交。

git reset 没有其他参数 unstages commits

I can view the history via Visual Studio and find the commit where I deleted those files. I tried ... Reset - Keep Changes, and Reset - Delete Changes. My files did not come back."

不,因为那是错误的提交。那是您删除文件 的提交。这意味着文件 不在提交 中。这就是删除的意思。

最后一次 包含 文件的提交是 上一个 提交。

您可以使用 git checkout 从该提交中按名称提取每个文件。语法是

git checkout SHA -- path/to/file

请记住,恢复的文件现在将在您的工作树中,但不会在您的下一次提交中,直到您 git add 它们。