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
- How do I get a file manifest for each revision in a git repository?
- How to merge conflicted file in your branch only in git?
- Remove deleted files from git history
- Do you know of a good pro/con paper on Version control system (git/mercurial/svn/cvs)?
- TFS: Git vs Team Foudation Version Control
- Do you version control the invidual apps or the whole project or both?
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?
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
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.