Does git commit –amend include the files that were in the last commit?

The git book seems to contradict itself re git commit --amend:

This command takes your staging area and uses it for the commit. If
you’ve made no changes since your last commit…, then your
snapshot will look exactly the same and all you’ll change is your
commit message.

First it says, “This command takes your staging area and uses it for the commit.”

Now, if I run git add -A; git commit -m "Initial"; git status; the status message says the staging area is empty.

Then the book says, “If you’ve made no changes since your last commit … your snapshot will look exactly the same…”

Now, if it uses my (empty) staging area for the commit, shouldn’t the amended commit be empty? The amended commit isn’t empty though, it includes the files that were in the last commit.

It seems that the git book should read:

This command takes your staging area, adds it to the last commit, and creates a new commit from the combination…

Please help me out here. What, if anything, am I missing?

  • http://git-scm.com/book/en/Git-Basics-Undoing-Things
  • http://git-scm.com/docs/git-commit

  • Gitflow with multiple master branches
  • How does the Eclipse CDT indexer cooperate with version control?
  • Testing and Managing database versions against code versions
  • How do I pull upstream changes of a remote GitHub repository?
  • Should github repo also have nuget packages folder?
  • How to get git and tfs to work side by side in MSVS2013?
  • How and/or why is merging in Git better than in SVN?
  • Different repositories for each module in intellij IDEA
  • One Solution collect form web for “Does git commit –amend include the files that were in the last commit?”

    The wording is a bit awkward, but your interpretation is correct. That’s exactly what --amend does.

    The book seems to be saying that it won’t automatically add unstaged changes to the commit.

    What happens instead, as you correctly note (and as the book does say, in an unclear way in my opinion), is that the old commit is replaced with another commit, which has the same changes as the original but a (Potentially) new commit message and a new timestamp and commit hash. That’s what it means by snapshot: the state of the repo at that moment in time.

    Of course, if you DID have staged changes, those changes will be rolled into the new commit.

    Git Baby is a git and github fan, let's start git clone.