Reputation: 13508
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....
Upvotes: 39
Views: 64641
Reputation: 28435
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.
Upvotes: 0
Reputation: 1591
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
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.|
This will recover all the missing changes to your local repository, commit and push and you should be good to go.
Upvotes: 3
Reputation: 61401
Tortoise Git
-> Show log
. Revert to this revision
.Hope this saves you some time.
Upvotes: 6
Reputation: 31337
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.
Upvotes: 27
Reputation: 1071
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.
Upvotes: 52