nicoorfi
10/1/2019 - 11:51 AM

Add changes to old commit

Use git rebase. Specifically:

  • Use git stash to store the changes you want to add.
  • Use git rebase -i HEAD~10 (or however many commits back you want to see).
  • Mark the commit in question (a0865...) for edit by changing the word pick at the start of the line into edit. Don't delete the other lines as that would delete the commits.
  • Save the rebase file, and git will drop back to the shell and wait for you to fix that commit.
  • Pop the stash by using git stash pop
  • Add your file with git add <file>.
  • Amend the commit with git commit --amend --no-edit.
  • Do a git rebase --continue which will rewrite the rest of your commits against the new one.
  • Repeat from step 2 onwards if you have marked more than one commit for edit.