简体   繁体   中英

TortoiseGit - Revert?

I am using 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.

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. Selecting TortoiseGit -> Revert... will display a window for you to select the files you want restored. 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 .

在此输入图像描述

  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 .

在此输入图像描述

Hope this saves you some time.

Git turns out a horrible nightmare when a merge commit occur. A merge often destroy some of the recent commits/changes. Here is a way to revert a merge and recover the changes via TortoiseGit.

1) Right mouse click at your repo, TortoiseGit->Show Reflog 第1步

2) Reflog dialog will appear, showing all the recent commits. 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.| 第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

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.

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.

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