Using git commit –fixup for amending changes
Knowing git a bit deeper gives you the chance to manipulate git history effortlessly.
git commit --fixup=0F0F0 gives you a handy tool for amending changes.
7d322df (HEAD -> master) Displaying file at a given git revision 211f4ff theme is now a reserved word 20873e9 Update gems
Suppose that I forgot to add some changes to commit 20873e9 (Update gems). Since the commit was added, another two commits have been added. In that situation you could:
- Add changes as a new commit
- Rebase interactively with
git rebase head~3and add the changes to 20873e9
- Add changes to staging and use
git commit --fixup=20873e9
Let’s try the last out!
git add Gemfile.lock git commit --fixup=20873e9 [master 8d88bc4] fixup! Update gems
The history will look something like this:
git log 8d88bc4 (HEAD -> master) fixup! Update gems 7d322df Displaying file at a given git revision 211f4ff theme is now a reserved word 20873e9 Update gems
Now, before pushing the changes run
git rebase -i head~4 pick 20873e9 Update gems fixup 8d88bc4 fixup! Update gems pick 211f4ff theme is now a reserved word pick 7d322df Displaying file at a given git revision
Save the changes and the changes will be merged. If something goes wrong, don’t worry:
git reflog is always at your disposal.
This protip has been written in 1071 seconds