Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell `git diff <commit>` to diff untracked files that used to be tracked in `<commit>`?

Tags:

git

git-diff

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!?

like image 603
kjo Avatar asked Feb 09 '14 01:02

kjo


People also ask

Does git diff show untracked files?

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.

How do I track untracked files in git?

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.

How do you check the diff of a commit?

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 .

How do I find the difference between two commits in git?

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


1 Answers

You can use

git diff --diff-filter=M

To show only the modified files and not the deleted ones

like image 177
exussum Avatar answered Oct 11 '22 09:10

exussum