Reputation: 10229
I read somewhere that each git add
is a new snapshot.
So, if on file X, I do some changes, a git add
, more changes and another git add
, how can I see the changes between the first and second call to git add
?
Upvotes: 1
Views: 71
Reputation: 851
What you read is wrong. git add
just adds changes or new files to the staging area (also called index). They will be included in the next commit which is probably the snapshot you are talking about. I don't think there is a way to show the difference between the staging areas after subsequent git add
calls. If you commit things you can see the difference between your working directory and the last commit with git diff
and the difference between your last two commits with git diff HEAD~1 HEAD
. Check man git diff
.
Upvotes: 0
Reputation: 1323813
You might look into older "add" with git fsck --full
, as mentioned in "Git Internals - Maintenance and Data Recovery".
This is similar to "Recovering added file after doing git reset --hard HEAD^
".
if you've added the object to the index (by using
git add
), there is a blob created for that state of the object - but there is no tree (and thus, commit) object that is referring to it.
This is how one gets a 'dangling' loose object file, and if you rungit fsck
it will show you the unreferenced blob (git gc will delete these types of objects if it is run).
So you can find those intermediate versions easily, because there isn't an file name referring those (since there is no tree, only blob): you have to look at their content.
Upvotes: 2
Reputation: 1009
Each git commit
is a new snapshot. git add
does not have any functionality for tracking when the changes you've made were added. You would have to commit after the first add and then use git diff
to see what has been changed (or, after you've already made the second add, git diff --cached
).
Upvotes: 0