Join me on Facebook!
— Written by Triangles on February 18, 2016 • updated on February 18, 2016 • ID 29 —
What to do when you forget to add one of the files the first time around?
Suppose you have just committed your beautiful changes in a clean commit, but suddenly you realize that there is a missing file, say
missing.py containing changes that should have been included before. What to do?
First of all add the file to the stage area, with the well-known
git add <your-file>. So for example, if you want to add
missing.py, just do
git add missing.py.
Now that the file is staged,
git commit --amend comes to the rescue. The
--amend flag is basically a way to fix up the most recent commit. Invoke it and the text editor will pop up: you may also change the commit message if needed.
Save the message and
missing.py will be properly included in your last commit. If you want to skip the message editing part, add the
--no-edit flag like that:
git commit --amend --no-edit. Sweet!