208

Is it possible to have git status only show the modified files due, in my case, to having too many staged files?

ΩmegaMan
  • 26,526
  • 10
  • 91
  • 107
chrisjlee
  • 19,976
  • 26
  • 76
  • 109
  • 1
    How do you have a scroll limit? By default, `git status` will invoke the pager. – Lily Ballard Apr 04 '12 at 20:16
  • Sorry scrollback limit is set to 512 lines on my machine. I guess i could change it; but would prefer a one line command to view just modified files in the status because GD/imagecache will generate even more files eventually. – chrisjlee Apr 04 '12 at 20:20
  • 1
    Right... my point is the pager doesn't use your terminal's scrollback. – Lily Ballard Apr 04 '12 at 20:26
  • Anything wrong with just grepping for whatever you find interesting? Use `--short` or `--porcelain` to get one-line versions of the status. – torek Apr 04 '12 at 20:26
  • 2
    One more point, based on the suggestion to use `git ls-files -m`: which modification(s) do you care about, staged, unstaged, or both? – torek Apr 04 '12 at 20:36

17 Answers17

312

You can't do this with git status, but you could use git ls-files -m to show all modified files.

Lily Ballard
  • 176,187
  • 29
  • 372
  • 338
  • 6
    Just so others know, this will only show files which have been modified without yet being staged. – Gerry Apr 15 '15 at 10:19
  • 21
    While this is the accepted answer, it has inaccurate information. You can "'git status' only modified files" with `git status | grep modified` just as user23186 indicates in their answer. – K. Alan Bates Jan 18 '16 at 17:00
  • @K.AlanBates My answer is correct. Your command is not running `git status` only on modified files, it's running `git status` on everything and then using a separate tool to throw away the unwanted info. Your answer also won't work if the user has the git config setting to always use short mode. A more accurate suggestion would have been `git status -s | grep '^.M'`, but even that is just a poor way of accomplishing the same thing as `git ls-files -m`. – Lily Ballard Jan 18 '16 at 19:02
  • To be more specific, the mention of 'inaccurate information' is only to your first clause declaring that "you can't do this with `git status`." You totally can have git status return only modified files with grep. Of course your suggestion to use `ls-files -m` will function just fine; its just not as expressive, in my opinion. – K. Alan Bates Jan 18 '16 at 19:53
  • 11
    For me, `git ls-files -m` is not showing anything but `git status | grep modified` is working. – Sandeepan Nath May 05 '16 at 11:41
  • @KevinBallard Can you give all option of `git ls-files`? – alhelal Dec 05 '17 at 05:28
  • 2
    As others have pointed out, this only shows unstaged files. If you want to show both unstaged AND staged files, this is the best answer I've seen: https://stackoverflow.com/a/39994894/452587 – thdoan Jan 18 '19 at 21:15
  • 2
    @thdoan There are a number of options for showing staged files, though this particular question seems to want to explicitly exclude staged files. `git diff --name-only --diff-filter=M HEAD` would show just modified files for both staged and unstaged, though you should check the docs on `--diff-filter` to see what other filter types you might want to add. – Lily Ballard Jan 19 '19 at 22:15
  • For better or worse, this solution will only show modified files in your current directory or its subdirectories. In other words, if you're in a subdirectory, it will not show you the modified files in your parent directory. IMO this is a drawback but I guess it's fine as long as you're aware of this fact. I suspect this is the explanation for Sandeepan Nath's comment and its numerous upvotes. I am surprised this hasn't been pointed out in 8 years. – ibonyun Sep 16 '20 at 23:47
70

It looks like git status -uno will show you only files that git is tracking, without showing anything else in the directory. Not exactly what you asked for, but perhaps accomplishes the same thing (getting a readable-length list of files that git tracks).

Kamal Reddy
  • 2,550
  • 4
  • 25
  • 36
TomNysetvold
  • 945
  • 6
  • 9
  • 1
    `git status -u no` does not show (1) tracked files which are modified, nor (2) tracked files which are staged. I've verified this with git versions 1.8.5.2 and 1.9.4. – mxxk Sep 12 '14 at 20:59
  • 4
    @TomNysetvold, you may actually mean `git status -uno` (http://stackoverflow.com/questions/7008546/command-git-status-u-no-filters-tracked-files-also) – mxxk Sep 12 '14 at 21:03
36

For modified files:

git status | grep modified:
Lance
  • 471
  • 5
  • 6
34
git status -s | awk '{if ($1 == "M") print $2}'
21

git diff --name-only --diff-filter=M

ZeroGraviti
  • 987
  • 1
  • 9
  • 23
  • 3
    I recommend those filters: `git diff --cached --name-only --diff-filter=ACMR` which does Added, Copied, Modified and Renamed files. – qwertzguy Jan 30 '18 at 01:17
10

git diff --name-only works too.

mpelzsherman
  • 618
  • 7
  • 9
6

You can use

$ git status -uno 

to list only modified files.

Karthik
  • 105
  • 1
  • 2
  • 11
5

I was looking for the same info and found following gives modified files:

git status -uno
Tectrendz
  • 1,266
  • 2
  • 17
  • 34
3

To list the modified files use:

git ls-files -m

If you want just the basename (no path) then you can pipe each result to the basename command using xargs, line by line:

git ls-files -m | xargs -L 1 basename
briggySmalls
  • 51
  • 1
  • 5
3

The problem is i have too many staged files that i don't want to commit or gitignore at the moment and i can't scroll up.

While this may not directly answer the question of listing only modified files, it may help limit the number of files that are listed.

You can pass a path to git status to limit the output to a specific folder in the repo.

For example:

git status app
git status spec
git status src/components
BillFienberg
  • 729
  • 10
  • 16
3

I use this command :

$ git status -sb -uno | grep -v "^\sD\s"

And the output looks like this :

## master...origin/master
 M GNUmakefile
 M include/mp4v2/project.h
SebMa
  • 3,181
  • 24
  • 32
2

Update

open the .gitconfig

[user]
     name = ...
     email = ...
[alias]
    #  add below code
    mySt = "!f() {\
        inputType=${1:-" "};\
        git status -s | grep "\\ $inputType" |\
        sed -e 's/ / /'   ;\
    }; f"

explain: https://stackoverflow.com/a/62772985/9935654

usage

git mySt M : show modified:

git mySt M *.md : Show all *.md, which was modified.

git mySt D : deleted:

git mySt : same as the git status -s


OS: windows

The following command will display all lines containing "modified:", "renamed:" or "new file:"

git status | findstr "modified: renamed: new file:"

If you want to specified file type: (for example *.py *.ini)

git status *.py *.ini | findstr "modified: renamed: new file:"

If you think it’s too much trouble typing so much:

  1. create a batch file (for example: st.bat)

  2. write contents as following:

    @echo off
    :: st.bat  (this line doesn't necessarily. ( just let you know the scripts name.))
    git status %~1 | findstr "modified: renamed: new file:"
    
  3. add environment path which contains your batch file. (st.bat)

  4. usage

    st.bat "*.py *.ini"
    

    (note: if type > 1 then must add the semicolon)

OS: LINUX

as @Lance says you can try

git status | grep modified:

Carson
  • 3,764
  • 2
  • 23
  • 33
1

One alternative is to have the results on a single line via -s which can limit what is being shown.

git status -s

Image of Git status -s

Shown under windows Terminal with Powerline/Posh git.


This command is so handy in that I added it as an alias used as git stati

[alias]
   stati = !git status -s
ΩmegaMan
  • 26,526
  • 10
  • 91
  • 107
0

I use git cola. Its a simple and elegant UI client that will show you the modified files and provide you with a diff like shot of the changes you made.

git cola provides you with a GUI where you can visualize which files you modified, which you staged, and even those you don't track. Your question was to use git status only I believe, but I thought git cola can help when that and other things as well. Check this web page from more info: git-cola.github.com/screenshots.html

chrisjlee
  • 19,976
  • 26
  • 76
  • 109
n_x_l
  • 1,502
  • 3
  • 16
  • 32
  • 2
    Could you provide how that relates to my answer given i'm not familiar with this git cola. e.g. screenshots, or more detail? – chrisjlee Apr 05 '12 at 03:10
  • it that why is was downvoted? :) Anyway, git cola provides you with a GUI where you can visualize which files you modified, which you staged, and even those you don't track. Your question was to use git status only I believe, but I thought git cola can help when that and other things as well. Check this web page from more info: http://git-cola.github.com/screenshots.html – n_x_l Apr 05 '12 at 15:07
  • How to change cola's interface language? – Ziyuan Oct 13 '14 at 14:21
0

If you want to list the modified files, you could do this:

git log -n1 --oneline --name-status | grep '^M'
Pang
  • 9,073
  • 146
  • 84
  • 117
David H.
  • 2,722
  • 1
  • 22
  • 18
0

To list all modified files use:

git show --stat --oneline HEAD
CertainPerformance
  • 313,535
  • 40
  • 245
  • 254
Fayaz
  • 41
  • 1
  • 3
0

All great answers; just FEI, "git checkout " (switching to or in the same branch) appears to show only modified files.

galaxis
  • 835
  • 8
  • 10