amending a single file in a past commit in git

git

Solution

If you only want to amend the second to last commit (eg. not long ago, especially not before many branches and merges), then I use this procedure:

- `git checkout -b tmp bad-commit`

- fix the files

- `git commit --amend`

- `git rebase tmp master`

If you have merges in between, you may wanna try `rebase -i -p`, but the results may vary.

Problem

I want to fix a file in past commit. This might affect all ascending commits. Is there an easy way to do that? Many times when I commit twice I find that I've had error in the first commit, and I wish to fix the error without having to `git reset` my last good commit. For clarification, I want to change the actual commit, that is, I want the content of the past commit to be changed. In other words, I want to change history!

Original source

Related problems