How to compare the working copy, staging copy and committed copy of a file using git
How do I compare the staged copy (the one with the year change) with working copy.
[...] I had the need to compare what I have staged with changes I subsequently made to the file
That would still be git diff
.
(edit by OP: How do I compare the committed copy (the one with the year change) with working copy
Then it would be git diff HEAD
.)
(365git: Getting a diff between the working tree and other commits)
If you are looking for something different from git diff
and diff --cached
, that leaves you with:
git diff HEAD
That is: the difference between the version already committed and the working tree.
- git diff - Compare working area to index.
- git diff --staged - Compare stage area to repository.
- git diff HEAD - Compare working area to repository
To illustrate that, I changed a file with “Name Staged” text and then I added it (git add .). After that, I changed the file again, now I replaced the text to “Name Working Area” and then I run the following commands:
Now, you can see clearly how it works. Pretty cool, right?