- Add the forgotten file
git add src/app.js - Put it into the last commit
git commit --amend --no-editThis keeps the same commit message. Leave out --no-edit if you also want to change the message.
- If you already pushed the commit
git push --force-with-leaseOnly do this on your own branch. It replaces the commit on GitHub and anyone who pulled the old one will need to pull again.
Check it worked
- Check the file is in the last commit
git show --stat HEADThe file should be in the list of changed files. Press q to leave.
Undo it
- Go back to the commit before you added the file
git reset --soft 'HEAD@{1}'The file stays added, ready for its own commit.
- Add the forgotten file
git add src/app.js - Put it into the last commit
git commit --amend --no-editThis keeps the same commit message. Leave out --no-edit if you also want to change the message.
- If you already pushed the commit
git push --force-with-leaseOnly do this on your own branch. It replaces the commit on GitHub and anyone who pulled the old one will need to pull again.
Check it worked
- Check the file is in the last commit
git show --stat HEADThe file should be in the list of changed files. Press q to leave.
Undo it
- Go back to the commit before you added the file
git reset --soft 'HEAD@{1}'The file stays added, ready for its own commit.
- Add the forgotten file
git add src/app.js - Put it into the last commit
git commit --amend --no-editThis keeps the same commit message. Leave out --no-edit if you also want to change the message.
- If you already pushed the commit
git push --force-with-leaseOnly do this on your own branch. It replaces the commit on GitHub and anyone who pulled the old one will need to pull again.
Check it worked
- Check the file is in the last commit
git show --stat HEADThe file should be in the list of changed files. Press q to leave.
Undo it
- Go back to the commit before you added the file
git reset --soft 'HEAD@{1}'The file stays added, ready for its own commit.

New to commit? I explain it in plain English on Layman Terms.