Undo git commit with TortoiseGit
commit, git, tortoisegit
Solution
Abstract
If you don't want to discard the working tree changes, using Reset with Mixed option or commit it with another branch to keep it.
If you want to keep changes in a commit, do what you want to do except clean up the repository(garbage collection). Those changes can be retrieved later.
Detail Steps
2023/12
Win10
TortoiseGit 2.15.1.0
git version 2.43.0.windows.1
Undo last commit: `Reset` with `Mixed` option
Condition:
- Working Tree has some changes and you want to keep it.
- Or, Working Tree is clean, but you want to keep local changes as same as last commit.
and
The result:
If pushing `F5` to refresh, that last commit will be invisible. I will show you how to retrieve that commit later.
Undo last commit: `Reset` with `Hard` option
If you don't care the Working Tree Changes nor the last commit's changes, perform Git Reset with Hard.
The result:
Also, that last commit will be invisible after pushing `F5`. But, it can be retrieved.
Retrieve invisible commit
You could create a local branch `keep` to keep the commit at the beginning. Like this:
If not... Since you have done the commit, that commit will exist in the near future. So you can find it back by using Reflog.
Then, you can show log for that invisible commit, or create a local branch for it.
NOTE: Those invisible commits will be accessible until the repository is cleaned up.
Undo/Remove the commit which is not the last one: `Rebase with Force`
and
(You may hit the conflicts, but how to resolve the conflicts is another story. :P )
The Result:
NOTE: Also, you can create `keep` branch at beginning or by using Reflog to retrieve it later. If so, the Graph of Show Log will be:
Problem
I'm using TortoiseGit in Windows for my git projects. I made a local commit on my project. And I want to undo it. How to undo git commit with TortoiseGit? without discarding my changes