1

Is there a way to git diff such that it shows changes to existing (tracked) files, but also changes to completely new files? I would like to make it my default way of viewing the diff, because that's, to me, a true diff (exclusion of untracked files is not a true difference between the last commit and the state of the repo).

Note if git diff cannot do what I'm after, in lieu of some way of making git diff show the diff between the last commit and the current state (including new files), using another command to achieve that would also be fine. TL;DR I would like to be able to see the diff between the last commit and the current state (including new files), and what git commands I use is not important. I should also note I do not wish to have to include, by name, each untracked file (some option like git diff --include-untracked would be ideal).

stevec
  • 41,291
  • 27
  • 223
  • 311
  • This could help: https://stackoverflow.com/a/52093887/112968 – knittl May 15 '22 at 12:08
  • @torek, I was thinking of proposing this as a new feature in Git software. You have a lot of experience, what do you think? The best alternative appears to be what knittl refers to, and it's super verbose, unmemorable, and unlikely to get used for those reasons. I think something like `git diff --include-untracked` would be excellent. The other reason is because the principle of least surprise would probably lean toward including untracked files. It's surprising that there's no easy way to do this with Git. – stevec May 15 '22 at 15:39
  • 1
    I agree that `-N` is klunky (and it used to be frequently broken). I'm not sure how easy it would be to get agreement on an option into `git diff` here, but you could easily write your own porcelain (a `git ndiff`) that runs `git status --porcelain` to find existing untracked files and generates a fake diff (or a file diff against `/dev/null`) for each. The likely objection to such an option is that in many large repositories, there are a ton of untracked *and ignored* files that should be skipped; the likely answer to that objection is that this should only display non-ignored files. – torek May 15 '22 at 15:44
  • 1
    To kick off such a discussion, see the Git mailing list (`git@vger.kernel.org`, and various archives). – torek May 15 '22 at 15:45

0 Answers0