简体   繁体   中英

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?

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.

Have a look at the 'EXAMPLES' section of man git-diff . It's very well explained there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM