Turns out to be quite simple, the answer found here. Suppose you’re on a branch
branch. Perform these steps:
create a temporary branch from the commit after you want to insert the new commit (in this case commit
git checkout -b temp A
perform the changes and commit them, creating a the commit, let’s call it
git commit -a -m "Message"
git addfollowed by
rebase the commits you want to have after the new commit (in this case commits
C) onto the new commit:
git rebase temp branch
delete the temporary branch:
git branch -d temp
After this, the history looks as follows:
A -- N -- B -- C
It is of course possible that some conflicts will appear while rebasing.
In case your branch is not local-only this will introduce rewriting history, so might cause serious problems.