I forgot to add a settings file that is needed in order for my project to run. I have made 14 commits already. How do I go back and add that settings file to the initial commit so that all of my commits have this file?
2 Answers
Its simple to do using git rebase which is available from git 1.7
Here are the steps to do it,
- Use - git rebase -i HEAD~14(takes you 14 commits back)
- Mark the commit for - edit. (this lets you edit the commit)
- Save the rebase file, and git will come back to the shell and wait for you to fix that commit 
- Add your settings file with - git add(this will add the file you forgot to add before to the old commit)
- Amend the commit with - git commit --amend(this amends or changes the old commit for you with the newly added file)
- Do a - git rebase --continuewhich will rewrite the rest of your commits to match the new one
Hope it helps!
 
    
    - 15,355
- 10
- 73
- 107
You can make the commit now and then use rebase to re-order the commits.
However, this will re-write the history of your repository so it's only really useful if your repo hasn't been distributed to others.
For example:
- git add <missing-file>
- git commit -m "Added missing file."
- git rebase -i HEAD~14
- Re-order the commits so your missing file commit is just after you added your untracked files earlier.
Before you start, please consult the documentation for rebase as it's a powerful command but it can also cause problems if used incorrectly. Documentation: https://git-scm.com/docs/git-rebase
I hope this helps.
 
    
    - 942
- 6
- 19
