Tanay
Tanay

Reputation: 181

Does git diff compare between index and working copy or last commit and working copy?

In the git reference, it is stated that

A simple git diff will display in unified diff format (a patch) what code or content you've changed in your project since the last commit that are not yet staged for the next commit snapshot.

What I did was, commited a file containing the text A.Then I changed the text in that file from A to B and staged it(did not commit). And at last, I changed the content of file to C. Now when I run git diff it shows me the difference between B and C. But I want to see the difference between A and C. How do I do it?

Upvotes: 4

Views: 1582

Answers (1)

e.doroskevic
e.doroskevic

Reputation: 2167

If you want to check difference between other things for instance look at the examples below:

You can run

git diff HEAD^       #check against parent of last commit
git diff HEAD^^      #check against grandparent of last commit
git diff HEAD~5      #check against 5 commits ago, 5 can be replaced with any number
git diff HEAD^..HEAD #check second most recent commit against most recent
git diff SHA1 SHA2   #check difference between two pre-defined commits
git diff --staged    #check staged vs current index (HEAD)

You can also do it based on time variation but that's a bit more advanced.

Upvotes: 8

Related Questions