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.
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.
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.
If you haven't pushed your changes yet (so your commit is only local)
TortoiseGit
-> Show log
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With