TIL: Use the --root flag in place of HEAD~N for editing the initial commit message
6/11/2026 · 5 min read
Context
I opted to edit a commit message but ran into trouble when using HEAD~N.
Nerd Activities
I was writing some benchmark tests this evening in Node.js, Python, and Rust. I wanted my commit messages to be more uniform (despite this being deployed absolutely nowhere), so I opted to rebase:
My first instinct is to reach for git rebase, but I uncovered a fundamental flaw in my understanding of N in HEAD~N.
I wound up running git rebase -i HEAD~1 and git rebase -i HEAD~2 just to make sure I wasn't losing it. As it turns out, HEAD~N means “go back N commits from the current tip.” Since there were only 3 commits, this triggered the error above.
Solution
I ultimately discovered the --root flag which allowed me to access the first commit message. My commit history now reads much cleaner: