If I want to see the differences between <commit>
and the working directory (WD), I run
% git diff <commit>
This usually does what I want, but it if the WD contains files that were being tracked at the time that <commit>
was created, but are not being tracked now (or in the current branch), then the resulting diffs treat these files in the WD as if they were /dev/null
.
I can imagine situations in which this would be the appropriate behavior, but at the moment I'd like to be able to see the "real" differences between <commit>
and the current directory, using the list of files that were being tracked at the time that <commit>
was created.
Is there some way to instruct git diff
to behave this way?
EDIT: if there were a way to stash away (and later restore) just the index, maybe running git reset <commit>
before git diff <commit>
would produce a full comparison between <commit>
and the WD, but I haven't yet figured out how to selectively stash away (and later restore) the index... Oh! I guess I could just do a "poor man's stash" like this: cp -a .git/index .git/index.bak
!?
With recent git versions you can git add -N the file (or --intent-to-add ), which adds a zero-length blob to the index at that location. The upshot is that your "untracked" file now becomes a modification to add all the content to this zero-length file, and that shows up in the "git diff" output.
You have to add the untracked files of the repository by using the “git add” command and run the “git stash” command to save the untracked file and clean the current directory for working by removing the untracked file from the repository folder.
To see the diff for a particular COMMIT hash, where COMMIT is the hash of the commit: git diff COMMIT~ COMMIT will show you the difference between that COMMIT 's ancestor and the COMMIT .
To see the changes between two commits, you can use git diff ID1.. ID2 , where ID1 and ID2 identify the two commits you're interested in, and the connector .. is a pair of dots. For example, git diff abc123.. def456 shows the differences between the commits abc123 and def456 , while git diff HEAD~1..
You can use
git diff --diff-filter=M
To show only the modified files and not the deleted ones
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With