til

today i learned

View on GitHub

Editing Old Commits Using CLI or with Lazygit

Whenever I needed to edit an old commit, be it a silly typo or a missing import I caught before pushing to a remote repository, I use the following git commands.

git log # look up the commit hash to be edited
git rebase --interactive 'abcdef^' # caret means its parent
# mark the commit as "edit" and apply changes
git commit --all --amend --no-edit
git rebase --continue

Using lazygit, the process is almost identical.