Git rebase -I is not that scary
6 hours ago
- #version-control
- #rebase
- #git
- The author expresses surprise at the common fear of git rebase -i among developers, even those more experienced, and aims to demystify it.
- Running git rebase -i HEAD~4 opens a text file with a list of recent commits and commands (pick, reword, squash, fixup, drop), which is a plan for changes, not an immediate action; users can abort with git rebase --abort.
- Interactive rebasing involves editing instructions per commit (e.g., rewording messages or dropping commits), creating new commits while leaving old ones intact in git's object database until garbage collection.
- Safety measures include: git rebase --abort to bail out, the reflog to restore previous states (e.g., git reset --hard HEAD@{4}), and creating a backup branch (git branch backup-before-rebase).
- Conflicts may arise during rebasing, but they are resolved one commit at a time (similar to merge conflicts) using git add and git rebase --continue, making them easier than branch merges.
- The author advises using rebase freely on personal feature branches and pushing with git push --force-with-lease (preferable over --force for safety), while emphasizing understanding and care.
- The key takeaway is that developers should learn and use interactive rebasing to maintain clean branch histories, with the post encouraging beginners to try it and overcome fear.