35

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....

August Lilleaas
  • 51,168
  • 11
  • 94
  • 107
Goober
  • 12,636
  • 49
  • 119
  • 188

4 Answers4

49

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.

Ryan Kearney
  • 1,041
  • 11
  • 14
  • 1
    I like to do this often with tortoise git often as temporary to determine if I introduced a bug. How do I update back to where I was though, after.. resetting a branch? – Flethuseo Apr 07 '14 at 18:10
25

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.

James Lawruk
  • 26,651
  • 19
  • 117
  • 128
6
  1. Right mouse on a directory or file you are plan on reverting, then Tortoise Git -> Show log.

enter image description here

  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.

enter image description here

Hope this saves you some time.

Matas Vaitkevicius
  • 49,230
  • 25
  • 212
  • 228
3

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 Step 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.| Step 2

This will recover all the missing changes to your local repository, commit and push and you should be good to go.

Farhan
  • 1,501
  • 14
  • 11