Git (TortoiseGit) - 如何将单个文件恢复到以前的版本,然后撤消恢复?
将 Git 与 TortoiseGit 一起使用时:有人知道如何将单个文件(或完整存储库)恢复到以前的版本吗?
例如,我有一个包含多个文件的存储库。一个文件存在三个修订版(1;2;3)。现在我想从版本 3 更改回版本 2。TortoiseGit
在“显示日志”对话框中提供了“恢复”功能,允许跳回到特定版本,但这将恢复整个存储库而不是单个文件。
此外,一旦我恢复了某些内容,我就不知道如何撤消恢复并跳回最新版本。
When using Git with TortoiseGit: Does somebody know how to revert a single file(or a complete repository) to a previous revision?
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.
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.
Also once I have reverted something, I don't have a clue how to undo the revert and jump back to the newest revision.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
从命令行:
git checkout
可能是您想要的。该文档显示了一个示例:
$ git checkout master~2 Makefile
将
Makefile
恢复为 master 分支中的两个修订版本在 TortoiseGit 中(通过 Windows 资源管理器),它看起来像您可以通过以下步骤执行此操作:
显示日志
Revert to this revision
1 files revert to e19a77
的消息From the command line:
git checkout
is probably what you want.The documentation shows an example of:
$ git checkout master~2 Makefile
to revert
Makefile
to two revisions back in the master branchFrom within TortoiseGit (via Windows Explorer) it looks like you can do this with the following steps:
Show log
from the TortoiseGit context menuRevert to this revision
1 files revert to e19a77
也可以获取特定文件:
TortoiseGit 显示一个包含所有修订版本列表的对话框
在底部的列表中对话框显示与提交关联的所有文件
例如:
- 原始文件是file.txt
- 修订版 2 将另存为 file-67b51a8.txt
我正在使用 TortoiseGit v2.2.0.0
It is also possible to get a specific file:
TortoiseGit show a dialog with a list of all revisions
In a list in the bottom of the dialog it shows all the files associated with the commit
For example:
- original file is file.txt
- revision 2 will save as file-67b51a8.txt
I'm using TortoiseGit v2.2.0.0
在 TortoiseGit 中,答案是右键单击项目文件夹并单击“显示日志”,然后右键单击要回滚到的更改并单击“切换/签出到此...”。然后,它会让您从提交堆栈中的那个奇怪的位置继续,或者如果您计划提交并希望事情保持理智,则可以分支。
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.
根据这些评论更新了我的答案:
假设工作树是干净的,您想要:
签出其先前版本的一些文件
(a) 右键单击要恢复的文件并显示该文件的日志
(b) 右键单击文件列表中的文件并执行恢复到父版本
(c) 重复 (a)、(b),直到获得所需的所有文件。
测试
恢复到当前版本
(a) 在资源管理器的上下文菜单中执行恢复...
这样,您就可以选择要恢复的文件。
(b) 或这种快速方法:在日志对话框中执行硬重置
这样,所有更改的文件都会恢复。 (=> 丢失所有工作目录更改)
(在 TortoiseGit 1.8.16.1、GfW 2.6.4.windows.1、Win 10 64 位上测试)
Updated my answer, based on these comments:
Suppose the working tree is clean and you want:
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 Hard in Log dialog
This way, all changed files revert. (=> Lost all working dir changes)
(Tested on TortoiseGit 1.8.16.1, GfW 2.6.4.windows.1, Win 10 64bit)
对于 Tortoise 版本 2.3.0:
您可以通过多种方式完成此操作,但我认为最快的是:
For Tortoise Version 2.3.0:
You can do it in several ways, but fastest i think is that: