Git Rebase Autosquash

Vanza Setia,

Estimated reading time: 1 minute

Problem

You have the following local commits:

edf23a5 (HEAD -> main) Make a legal page
88c90a5 Make a contact page
70d0caa Make an about page
eecd26c Make a homepage

The problem is you find a typo on the contact page, and you do not want to make a new commit.

Solution

You can solve it with git rebase.

git commit --fixup COMMIT_HASH
git rebase -i --autosquash COMMIT_HASH

Steps:

  1. Copy the commit hash that you want to fix.
  2. Execute git commit --fixup 88c90a5.
  3. Copy the commit hash before the commit that you want to fix.
  4. Execute git rebase -i --autosquash 70d0caa.
  5. Close the editor.

Once you are done, you get a new commit hash for the targeted commit and the commit above it.

2a37136 (HEAD -> main) Make a legal page
608b1eb Make a contact page
70d0caa Make an about page
eecd26c Make a homepage
Share your thoughts

Topic(s).

Thank you for reading this Git Rebase Autosquash. You can subscribe to all my articles with the Articles RSS. If you have a positive or negative comment, please send me an email or contact me through one of my social media accounts.

Share with your network

Copy this link and send it to great people only.

https://vanzasetia.xyz/blog/git-rebase-autosquash/

For you