Commit Manipulation and Reflog
Last updated
Last updated
In many projects, commits are more than a snapshot. It should represent a working state of the repository. That means, some projects don't really like it if you have a typo, then you have to create a separate commit to fix said typo.
So then, how do we rewrite the commit to fix the typo? That's where commit manipulation comes in.
Notice that the master branch changes to the new commit. That is, there will be no way to checkout the commit A unless you know the exact hash you are looking for.
Amending a commit adds some changes to an additional commit and "destructively" replaces the previous commit from it. This could be changes to the file, the author, or commit message, or even a combination of everything.
To do this is lazygit:
Move your head to the commit to amend
Make some changes and stage it
Hit A to amend the current commit with the changes
That's pretty cool, but what if I screw up, and want to look at the commit before I amended it? There are no pointers or labels now pointing at my old commit? That's where reflog comes into play.
Reflog is essentially a history of all the commits your HEAD has touched. It also keeps track of the hashes so that you can easily navigate between commits that might have been lost otherwise.
To use reflog:
Click on the reflog tab
Navigate the the commit you want, hit space to checkout
You can also hit C to cherry pick the commit if you want to apply it to your current branch