简体   繁体   中英

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. How can I recover those files?

I can view the history via Visual Studio and find the commit where I deleted those files. 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.

git reset without other args 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."

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

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