Situation: I'm working on a feature branch with multiple commits that are all part of a single pull request. I noticed that the 3rd last commit (i.e. HEAD~3) isn't correct and needs to be updated. In this specific situation I missed the removal of two binary files. The patch that I applied didn't remove them. No sweat, we still can fix this without having to mess with the latest two commits.
- Start the interactive rebase via the
git rebase -i HEAD~3command. HEAD~3 allows us to work with the three most recent commits.
In the interactive editor we replace the pick of the commit we want to edit with the edit command to amend to this commit.
After saving and closing the editor git will rebase and prompt us to do our amendments.
Now we can do the needed modifications to this specific commit. In my case it's the removal of the two binary files. Removal of files need an additional flag when performing the
--allin this case works well.
git commit --amendto commit your amended commit. You now get the opportunity to update the original commit message. As usual do a save and close to continue.
- Now use
git rebase --continueto finish up the rebasing.
- Push the changes to the GitHub repository via
git push --force origin <branch>