简体   繁体   English

TortoiseGit - 恢复?

[英]TortoiseGit - Revert?

I am using TortoiseGit.我正在使用 TortoiseGit。 I want to revert back to a point earlier before i had deleted a few images.我想恢复到我删除一些图像之前的一个点。

How do i do this, the methods of reverting that i have seen are incorrect....我该怎么做,我看到的恢复方法不正确....

Right click your working directory and select Show Log from the TortoiseGit menu. 右键单击您的工作目录,然后从TortoiseGit菜单中选择Show Log。

After that you can right click previous commits and reset the branch to that commit. 之后,您可以右键单击先前的提交并将分支重置为该提交。

If you deleted a few files and you have not made a commit yet, Revert will work just fine. 如果您删除了一些文件并且尚未提交, Revert将正常工作。 Selecting TortoiseGit -> Revert... will display a window for you to select the files you want restored. 选择TortoiseGit - > Revert ...将显示一个窗口,供您选择要恢复的文件。 Deleted files will show in red. 删除的文件将显示为红色。

If you already committed the delete, then you can Reset to a commit before you deleted the files. 如果您已提交删除,则可以在删除文件之前重置为提交。 Be warned that if you use reset, you will no longer see in your log the commit(s) after the commit you reset to. 请注意,如果使用重置,则在重置提交后,您将不再在日志中看到提交。

If you want to preserve in your log the commit that deleted the files, you can Checkout the commit before the delete into a new branch, copy the restored files into a separate folder, switch back to your original branch, then add the files back to your original branch. 如果要在日志中保留删除文件的提交,可以在删除之前检出提交到新分支,将恢复的文件复制到单独的文件夹,切换回原始分支,然后将文件添加回你的原始分支。

  1. Right mouse on a directory or file you are plan on reverting, then Tortoise Git -> Show log . 右键单击您计划还原的目录或文件,然后使用Tortoise Git - > Show log

在此输入图像描述

  1. Select at the top of window revision you want to revert to then at the bottom part of the screen Right mouse on any file and choose Revert to this revision . 选择要恢复到的窗口修订版顶部,然后在屏幕底部选择鼠标右键放在任何文件上,然后选择“ Revert to this revision

在此输入图像描述

Hope this saves you some time. 希望这能为您节省一些时间。

Git turns out a horrible nightmare when a merge commit occur. 当合并提交发生时,Git发现了一个可怕的噩梦。 A merge often destroy some of the recent commits/changes. 合并通常会破坏一些最近的提交/更改。 Here is a way to revert a merge and recover the changes via TortoiseGit. 这是一种通过TortoiseGit恢复合并并恢复更改的方法。

1) Right mouse click at your repo, TortoiseGit->Show Reflog 1)右键单击您的仓库,TortoiseGit-> Show Reflog 第1步

2) Reflog dialog will appear, showing all the recent commits. 2)将出现Reflog对话框,显示所有最近的提交。 Right mouse click the Merge commit (the one that caused the problem) and then select the option "Revert change by this commit" -> Parent 2 as shown in the image.| 用鼠标右键单击Merge提交(导致问题的提交),然后选择“通过此提交还原更改”选项 - >父级2,如图所示。 第2步

This will recover all the missing changes to your local repository, commit and push and you should be good to go. 这将恢复本地存储库,提交和推送的所有缺失的更改,你应该很高兴。

I've done as it was suggested in James Lawruk answer我已经按照James Lawruk 回答中的建议做了

If you already committed the delete, then you can Reset to a commit before you deleted the files.如果您已经提交了删除,那么您可以在删除文件之前重置为提交。 Be warned that if you use reset, you will no longer see in your log the commit(s) after the commit you reset to.请注意,如果您使用重置,您将不再在您的日志中看到您重置后的提交。

I've got what I wanted locally.我在当地得到了我想要的东西。 But when I tried to push the reverted version to remote server, git asked to pull the latest first, effectively restore the latest version from the server.但是当我尝试将恢复的版本推送到远程服务器时,git 要求先拉取最新版本,有效地从服务器恢复最新版本。

I had to push my “reset” local state to a new remote branch , and then merge the new remote branch into main remote branch.我不得不我的“重置”本地状态送到一个新的远程分支,然后新的远程分支合并到主远程分支中。

It is a good practice anyway, but it is not obvious that direct push does not work.无论如何这是一个很好的做法,但并不明显直接推送不起作用。

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

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