I have a branch with 2 commits. I need to add a 3rd commit before both of them. Normally I'd simply add a new tip commit, do git rebase -i
and then move it to the top (make it the first commit on the branch). However, I cannot do this since the specific change in question impacts code changed by the previous 2 commits, and I need to make this change before those changes (to avoid unnecessary conflicts).
At the moment the only way I've been able to accomplish this is to do roughly this:
$ git rebase -i origin/master
- mark top commit as edit (oldest commit)
$ git reset --soft @^
$ git stash save 'Last commit'
- make some code changes
$ git commit -am 'New commit'
$ git stash pop
$ git commit -aC @{2}
(commit the previous commit again, with same message)$ git rebase --continue
(until finished)
This is a lot of steps, and it's messy. It would be nice to be able to mark the commit BEFORE my branch's first commit as an edit and then just commit on top of that. But that won't work, if my merge-base
is a merge commit. I tried this:
$ git rebase -i origin/master^
I also tried:
$ git rebase -i origin/master^2
Both parents on the merge commit as my base. However, I get a ton of extra commits in the todo file, I'm not sure why.
What is an easy and intuitive method of accomplishing this?