April 15, 2024
There are (at least) two ways to view the diff of both an untracked file and tracked-but-changed/not-staged files in git.
-
Add the untracked file, run
git diff HEAD. If it turns out you don't want that file added, just follow the command shown on withgit status:git restore --staged <file>. -
Use the
-N(--intent-to-add) flag ingit add, which "record[s] only the fact that the path will be added later" (fromgit add --help). As the help continues, "This is useful for, among other things, showing the unstaged content of such files withgit diffand committing them withgit commit -a."
Not sure which way I'll settle on, but I'm glad I finally looked into it. I generally do the first version, but only because I didn't know any other way. And before I end up doing that, I usually think there is some simple flag I'm missing with git diff that'll do what I want, before realizing - once again - that there's not.