1

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?

Laoujin
  • 9,962
  • 7
  • 42
  • 69

3 Answers3

2

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 run git 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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Since this is the correct answer, I'll mark it as such. However it is also quite "hardcore", so instead I learned about `git commit --amend` and `git rebase` and changed my workflow so I don't need these advanced "internal" commands. – Laoujin Feb 11 '15 at 14:58
0

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).

Derek Redfern
  • 1,009
  • 12
  • 18
0

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.

Robert Rüger
  • 851
  • 9
  • 21