Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git (TortoiseGit) - How to revert a single file to a previous revision and then undo the revert?

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.

like image 588
Alexander Avatar asked Nov 03 '09 20:11

Alexander


People also ask

How do I undo a revert in TortoiseGit?

If you want to undo a deletion or a rename, you need to use Revert on the parent folder (or commit or repository status dialog) as the deleted item does not exist for you to right-click on. If you want to undo the addition of an item, this appears in the context menu as TortoiseGit → Delete (keep local).

How do I undo a previous commit?

The easiest way to undo the last Git commit is to execute the “git reset” command with the “–soft” option that will preserve changes done to your files. You have to specify the commit to undo which is “HEAD~1” in this case. The last commit will be removed from your Git history.


1 Answers

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 branch

From within TortoiseGit (via Windows Explorer) it looks like you can do this with the following steps:

  • Navigate in Explorer to the folder where the file is.
  • Right-click on the file you want to revert, choose Show log from the TortoiseGit context menu
  • In the top section ("graph") select the revision that has the version of the file you want to revert to
  • In the third section (file list) right-click the file and choose Revert to this revision
  • You should get a message like 1 files revert to e19a77
  • like image 123
    mlibby Avatar answered Sep 28 '22 12:09

    mlibby