0

How do I show only filenames for all modified files in my repository? git status adds additional output, e.g.,

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)
    modified:   my-file (modified content)

How do I get:

$ git status --name-only   # --name-only is not a valid option; what do I use instead?
my-file
Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
  • There isn't one. But `git status` is just one of many Git tools. If you want different results, use different tools, such as `git diff --name-only`. (I see this was a self-answer, and have upvoted your answer, since it's, well, the answer.) – torek Sep 11 '22 at 21:27

2 Answers2

1

There's an output option which does pretty much what you asked.

Only paths, with a letter to indicate A(dded), (M)odified, and so on.

git status -s [-b]
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
  • 1
    That's close @RomainValeri, but I don't want the prefixed letters ( (A)dded, (M)odified, ...). I know I could strip those off using something like `sed`, but am wondering if there's a way to do it without that. See my answer using "git diff". – Rob Bednark Sep 11 '22 at 18:20
0

Instead of git status, use git diff, e.g.,

$ # Show modified, unstaged files, and only the filenames
$ git diff --name-only --diff-filter=u
my-file

$ # Show modified, staged/cached files, and only the filenames
$ git diff --name-only --diff-filter=u --cached
my-staged-file
Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
  • This unfortunately doesn't take into account staged files. If you wanted only *unstaged* files, it should have been in the question. – Romain Valeri Sep 12 '22 at 15:33
  • @RomainValeri I have now updated the answer to how to take into account staged/cached files with the `--cached` option – Rob Bednark Sep 13 '22 at 14:21