Does git commit -amend include the files that were in the last commit?
The git book seems to contradict re itself git commit --amend
:
This command takes your staging area and uses it to commit. If you haven't made any changes since your last commit ... then your snapshot will look exactly the same and all changes will be a commit message.
First, he says, "This command takes your staging area and uses it to 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 haven't made any changes since you last took it ... your snapshot will look exactly the same ..."
Now if it uses my (empty) staging area to commit, shouldn't the patch with patch be empty? The modified commit is not empty, although it includes the files that were in the last commit.
It seems like 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 here. What if anything am I missing?
source to share
The wording is a little awkward, but your interpretation is correct. What it does --amend
.
The book seems to say that it won't automatically add unsettled changes to commit.
What happens instead, as you correctly noted (and as it appears from the book, in an obscure way in my opinion), is that the old commit is replaced with another commit that has the same changes as the original, but a (Potentially ) new commit message and new timestamp and hash commit. This is what it means with a snapshot: the state of the repo at that point in time.
Of course, if you've made phased changes, those changes will be carried over to the new commit.
source to share