简体   繁体   English

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

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

I've been using GIT with Visual Studio 2019. I accidentally deleted several files and committed that delete.我一直在使用 GIT 和 Visual Studio 2019。我不小心删除了几个文件并提交了删除。 How can I recover those files?我怎样才能恢复这些文件?

I can view the history via Visual Studio and find the commit where I deleted those files.我可以通过 Visual Studio 查看历史记录并找到我删除这些文件的提交。 I tried Revert, Reset - Keep Changes, and Reset - Delete Changes.我尝试了还原、重置 - 保留更改和重置 - 删除更改。 My files did not come back.我的文件没有回来。

What do I have to do to recover those files?我该怎么做才能恢复这些文件?

Find the commit which deleted the files and revert it, then commit that revert!找到删除文件并还原它的提交,然后提交该还原!

In a shell, this would be git log to see the log of commits, and then git revert aaaaaa where aaaaaa is the offending commit.在 shell 中,这将是git log以查看提交日志,然后git revert aaaaaa其中aaaaaa是违规提交。

git reset without other args unstages commits git git reset没有其他参数取消提交

I can view the history via Visual Studio and find the commit where I deleted those files.我可以通过 Visual Studio 查看历史记录并找到我删除这些文件的提交。 I tried... Reset - Keep Changes, and Reset - Delete Changes.我试过......重置 - 保留更改和重置 - 删除更改。 My files did not come back."我的文件没有回来。”

No, because that's the wrong commit.不,因为那是错误的提交。 That's the commit where you deleted the files .那是您删除文件的提交。 That means the files are not in the commit .这意味着文件不在 commit 中 That is what delete means.这就是删除的意思。

The last commit containing the files is the previous commit.包含文件的最后一次提交是上一次提交。

You could use git checkout to extract each of those files by name from that commit.您可以使用git checkout从该提交中按名称提取每个文件。 The syntax is语法是

git checkout SHA -- path/to/file

Keep in mind that the recovered files will now be in your worktree but not in your next commit until you git add them.请记住,恢复的文件现在将在您的工作树中,但在您git add之前不会在您的下一次提交中。

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

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