使用 Git Extensions for Visual Studio 将单个文件还原到较早的提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5201088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Revert a single file to earlier commit using Git Extensions for Visual Studio
提问by Brady Moritz
I've found instructions on how to revert a single file in a Git repository to an earlier version. But I am curious if anyone knows of a way to do this using Git Extensions for Visual Studio. This tool works great so far and I really like it, but I can't figure out how to do this one thing.
我找到了有关如何将 Git 存储库中的单个文件恢复到早期版本的说明。但是我很好奇是否有人知道使用 Git Extensions for Visual Studio 执行此操作的方法。这个工具到目前为止效果很好,我真的很喜欢它,但我不知道如何做这件事。
回答by Henk
The easiest way to do this in Git Extensions is to open the file history (e.g., from the context menu in Visual Studio) for the file you want to revert. Then find the revision you need and choose "Save As" in the context menu.
在 Git Extensions 中执行此操作的最简单方法是打开要还原的文件的文件历史记录(例如,从 Visual Studio 中的上下文菜单)。然后找到您需要的修订并在上下文菜单中选择“另存为”。
To revert changes made to a file in the working directory, just choose "revert changes" from the context menu in Visual Studio.
要还原对工作目录中的文件所做的更改,只需从 Visual Studio 的上下文菜单中选择“还原更改”。
回答by Sri Sankaran
While the technique suggested by @Henk will work, here's the Git way.
虽然@Henk 建议的技术可行,但这是 Git 的方式。
- Select the commit that changed the file you wish to revert.
- Choose the revert commit operation. Be sure you tell Git Extension not toautomatically commit the revert operation. This will result in a) A revert operation on the affected file(s) and b) Reverted file(s) being staged
- 选择更改了要还原的文件的提交。
- 选择还原提交操作。请务必告诉 Git Extension不要自动提交还原操作。这将导致 a) 对受影响文件的恢复操作和 b) 恢复的文件被暂存
Then you can unstage the file(s) that you do not wish reverted-- leaving only the one file that you do wishto revert to be committed.
然后你就可以unstage该文件(S) ,你不希望恢复-只留下了一个文件,你确实希望恢复到被提交。
While this might seem more tedious that just File > Save As, it comes in handy when you have to revert a handfulof files.
虽然这看起来比文件 > 另存为更乏味,但当您必须还原少量文件时,它会派上用场。
回答by Ritch Melton
Edited my post. I don't know why I responded about mercurial. Sorry about that. The same idea goes for git. I used tortiseGit (when I used git), but the command line is easier. TortiseGit is still a right click to revert. The command line is just 'git checkout filename' to get the checkout from the HEAD.
编辑了我的帖子。我不知道为什么我回应了 mercurial。对于那个很抱歉。同样的想法也适用于 git。我使用了 tortiseGit(当我使用 git 时),但命令行更容易。TortiseGit 仍然是右键单击即可恢复。命令行只是 'git checkout filename' 以从 HEAD 获取结帐。