shellstreak

Add a forgotten file to the last commit

Careful: rewrites history

Short answer

Stage the file, then run git commit --amend --no-edit. The last commit now includes it, with the same message.

Like any amend, this replaces the last commit. Only do it before you push.

The commands, one by one

  1. 1git add muffins.txt

    Stages the file you forgot.

  2. 2git commit --amend --no-edit

    Rebuilds the last commit with what's staged now. --no-edit keeps the commit message as it was.

For your own repository: Use your own file name in git add.

Try it safely

You committed Add muffins but left the new muffins.txt out.

learner@shellstreak: ~
Starting your practice shell…

Type your own commands too. Reset puts the repository back to just after the mistake.

Practise this in 5 minutes

Lesson 62, Commits a reviewer can read, walks you through this undo and the ones around it in a safe terminal, step by step, and checks your answers.

Keep the terminal cheat sheet handy: free to print

Get the shellstreak newsletter

Short terminal and Git tips you can try in a minute, plus a heads-up when new free tools and lessons ship. It lands now and then, never a flood.

No spam, unsubscribe in one click.