windows Git (TortoiseGit) - 如何将单个文件恢复到以前的版本,然后撤消恢复?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1669917/
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
Git (TortoiseGit) - How to revert a single file to a previous revision and then undo the revert?
提问by Alexander
When using Git with TortoiseGit: Does somebody know how to revert a single file(or a complete repository) to a previous revision?
将 Git 与 TortoiseGit 一起使用时:有人知道如何将单个文件(或完整存储库)恢复到以前的修订版?
For example I have a repository containing multiple files. One file exists in three revisions (1 ; 2 ; 3). Now I want to change from revision 3 back to 2.
例如,我有一个包含多个文件的存储库。一个文件存在于三个修订版 (1 ; 2 ; 3) 中。现在我想从修订版 3 改回 2。
TortoiseGit offers a "Revert" function in the "Show log" dialog which allows to jump back to a specific revision, but this will revert your whole repository instead of a single file.
TortoiseGit 在“显示日志”对话框中提供了“恢复”功能,允许跳回特定修订,但这将恢复整个存储库而不是单个文件。
Also once I have reverted something, I don't have a clue how to undo the revert and jump back to the newest revision.
此外,一旦我恢复了某些内容,我就不知道如何撤消恢复并跳回最新的修订版。
回答by mlibby
From the command line: git checkout
is probably what you want.
从命令行:git checkout
可能是您想要的。
The documentation shows an example of:
该文档显示了以下示例:
$ git checkout master~2 Makefile
$ git checkout master~2 Makefile
to revert Makefile
to two revisions back in the master branch
Makefile
在 master 分支中恢复到两个修订版
From within TortoiseGit (via Windows Explorer) it looks like you can do this with the following steps:
从 TortoiseGit 中(通过 Windows 资源管理器),您似乎可以通过以下步骤执行此操作:
Show log
from the TortoiseGit context menuShow log
从 TortoiseGit 上下文菜单中选择Revert to this revision
Revert to this revision
1 files revert to e19a77
1 files revert to e19a77
回答by Chris Moschini
In TortoiseGit the answer is to right-click the project folder and click Show Log, then right-click the change you want to roll back to and click Switch/Checkout to this... . It will let you then proceed from that weird place in the commit stack, or branch in case you plan to commit and want things to stay sane.
在 TortoiseGit 中,答案是右键单击项目文件夹并单击 Show Log,然后右键单击要回滚到的更改并单击 Switch/Checkout to this... 。然后它会让你从提交堆栈中那个奇怪的地方开始,或者在你计划提交并希望事情保持理智的情况下分支。
回答by mxmoss
It is also possible to get a specific file:
也可以获取特定文件:
- Right-click on the file
- Choose the menu item: Git Show Log
- 右键单击文件
- 选择菜单项:Git Show Log
TortoiseGit show a dialog with a list of all revisions
TortoiseGit 显示一个包含所有修订列表的对话框
- Click on the prior revision (2)
- 点击之前的修订版 (2)
In a list in the bottom of the dialog it shows all the files associated with the commit
在对话框底部的列表中,它显示了与提交相关的所有文件
- Find the file you are looking to view
- Right-click on that file and Save Revision To
- This will save that previous revision of the file with the commit number concatenated on the file
- 找到您要查看的文件
- 右键单击该文件并将修订版保存到
- 这将保存文件的先前修订,并在文件上连接提交号
For example: - original file is file.txt - revision 2 will save as file-67b51a8.txt
例如: - 原始文件是 file.txt - 修订版 2 将保存为 file-67b51a8.txt
I'm using TortoiseGit v2.2.0.0
我正在使用 TortoiseGit v2.2.0.0
回答by Yue Lin Ho
Updated my answer, based on these comments:
根据这些评论更新了我的答案:
Suppose the working tree is clean and you want:
假设工作树是干净的并且您想要:
- Checkout some file(s) of its previous revision
- Testing
- Revert to current revision
- 签出其先前修订版的一些文件
- 测试
- 恢复到当前版本
Checkout some file(s) of its previous revision
(a) Right click the file you want to revert and Show Log for that file
(b) Right click the file in file list and perform Revert to parent revision
(c) repeat (a), (b) until you get all files you want.
Testing
Revert to current revision
(a) perform Revert...in context menu of explorer
This way, you can choose the file(s) you want to revert.
(b) or this quick way: perform Reset Hardin Log dialog
This way, all changed files revert. (=> Lost all working dir changes)
签出其先前修订版的一些文件
(a) 右键单击要还原的文件并显示该文件的日志
(b) 右键单击文件列表中的文件并执行Revert to parent revision
(c) 重复 (a), (b) 直到您获得所需的所有文件。
测试
恢复到当前版本
(a)在资源管理器的上下文菜单中执行Revert...
这样,您可以选择要还原的文件。
(b) 或这种快速方法:在日志对话框中执行重置硬
这样,所有更改的文件都会恢复。(=> 丢失了所有工作目录更改)
(Tested on TortoiseGit 1.8.16.1, GfW 2.6.4.windows.1, Win 10 64bit)
(在 TortoiseGit 1.8.16.1、GfW 2.6.4.windows.1、Win 10 64 位上测试)
回答by Ovsyanka
For Tortoise Version 2.3.0:
对于乌龟 2.3.0 版:
You can do it in several ways, but fastest i think is that:
您可以通过多种方式做到这一点,但我认为最快的是:
- Right click on the file
- Click the menu option "Diff with previous version"
- Right click on the left (previous) version of file
- Click the menu option "Use this whole file"
- Save the changes (ctrl+s)
- 右键单击文件
- 单击菜单选项“与以前的版本不同”
- 右键单击文件的左侧(上一个)版本
- 单击菜单选项“使用整个文件”
- 保存更改 (ctrl+s)