git diff with respect to working tree including untracked files

Viewed 2329

I have an old commit A. I am now at commit B=HEAD!=A, and want to compare the state of my working directory, INCLUDING untracked files, with A.

The reason is that the currently untracked files were part of commit A, so they wouldn't show up in, and thus wouldn't clutter, the diff I desire.

As a workaround, I could manually git add <all the untracked files> before the diff and git reset <all the untracked files> after. However, there are many untracked files, and I would like to do this in a maximally atomic and robust way, as I am doing all of this in a script.

EDIT: This question also concerns diff against untracked files. However, the answers there require manual adding and later removing of untracked files, and I preferred a solution that does this more automatically and in an atomic way that is error proof against interruptions in a scripted context. The accepted answer does exactly this, and indeed is different from the answers to the linked question.

2 Answers
Related