I have committed a change and forgot to add a file to the change set. After other commits, I realized the file is now missing from a HEAD^4
commit.
How do I
If you have NOT pushed these 4 commits, you can do it as follows:
Create patch files for all these commits:
git format-patch -4
Rewind back by 4 commits:
git reset --hard HEAD~4
Add missing file:
git add missing-file
Commit it with --amend
:
git commit --amend
Apply all saved patches back:
git am *.patch
If you have pushed, you should NOT use this method. Instead, just admit your blunder and create one more commit on top of HEAD which fixes this issue.