Add changes to commits in the middle in Git

Viewed 12176

How to add the new changes to the commits which are in the middle, I mean not adding to the top commit.

git log
commit1 <--- HEAD
commit2
commit3

How to add the changes directly to commit3, without removing commit1 and commit2 and then adding changes to the commit3.

Do I need to use stash?

If possible, please provide the link.

4 Answers

You could use git reset --soft HEAD [commit3-hash]. this command remove the commit1 and commit2 from the history but its changes is still in there.

Related