Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tortoisegit undo last commit into the repo

Is there an option in tortoisegit to undo the last commit into the repo?

By mistake I pushed a large number of unnecessary files into my git repository(branch:master) which I need to undo. I have searched a lot for the right option in tortoise git to undo the push and go back to the state before the last commit. Please show me a way to undo my last commit.

like image 907
user2742122 Avatar asked Oct 02 '13 11:10

user2742122


People also ask

How do I undo last 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.

How do I revert last commit in remote repository?

To undo the last commit from a remote git repository, you can use the git reset command. command. This will undo the last commit locally. command to force push the local commit which was reverted to the remote git repository.


1 Answers

If you haven't pushed your changes yet (so your commit is only local)

  1. TortoiseGit -> Show log
  2. Select the commit to which you want to rollback to
  3. Reset "<branch>" to this...

If you have, then this can still be done, but then you'd have to also do a force-push (check "overwrite known changes" 1).

1The "overwrite known changes" flag will replace the already pushed commit with a new one. If there is a chance that someone already fetched the commit that you're replacing, don't use this feature, otherwise doing so will create a fork in the history with two conflicting truths.


There is also a shortcut for when you want to just (1) redo the last commit and (2) you haven't pushed it yet:

  1. Commit -> Check "Amend Last Commit"

That will replace the last commit with a new one. But I don't recommend using this - if the last commit is already pushed, you can end up with a big mess. TortoiseGit will not stop you here.

By doing a Reset you are forced to have a look at the log, and there you see if the commit is local or not.

like image 71
rustyx Avatar answered Oct 04 '22 00:10

rustyx