Commit Manipulation and Reflog

Commit Manipulation

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.

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

Reflog

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

Last updated