245

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

5
  • 1
    How do you have a scroll limit? By default, git status will invoke the pager. Commented Apr 4, 2012 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. Commented Apr 4, 2012 at 20:20
  • 1
    Right... my point is the pager doesn't use your terminal's scrollback. Commented Apr 4, 2012 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. Commented Apr 4, 2012 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? Commented Apr 4, 2012 at 20:36

19 Answers 19

368

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

Sign up to request clarification or add additional context in comments.

10 Comments

Just so others know, this will only show files which have been modified without yet being staged.
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.
For me, git ls-files -m is not showing anything but git status | grep modified is working.
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: stackoverflow.com/a/39994894/452587
@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.
|
83

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).

2 Comments

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.
@TomNysetvold, you may actually mean git status -uno (stackoverflow.com/questions/7008546/…)
43

For modified files:

git status | grep modified: 

2 Comments

So useful I've created an alias for this: git config --global alias.modified '!git status | grep modified:'
It's better to use git status -uno. If you prefer more terse output, then use git status -s -uno or git status -suno. Note: It's VERY IMPORTANT not to use a space between the -u option and its argument, no.
35
git status -s | awk '{if ($1 == "M") print $2}' 

1 Comment

Or awk '$1 == "M" { print $2 }'
30

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

4 Comments

I recommend those filters: git diff --cached --name-only --diff-filter=ACMR which does Added, Copied, Modified and Renamed files.
@qwertzguy ....for only modified files? No.
@RomainValeri: seems like you only read the title of the question. The OP is actually asking how to show only the unstaged changes (so "modified" since staging the changes), regardless of whether it's modified, copied, added or renamed. So my comment is actually closer to what the OP is asking than this answer. If you want to see all modified files (regardless of whether they are staged or not), then the correct command is git diff HEAD --name-only --diff-filter=M (which is also different from this answer).
@qwertzguy Sorry, I don't see yet where you get that OP wants modified files and renamed/added/copied? I might have missed it.
12

git diff --name-only works too.

Comments

9

You can use

$ git status -uno 

to list only modified files.

Comments

6

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 

1 Comment

Clever use of the xargs for ditching the path. That's got applications extending WAY beyond this particular use-case. Thanks a bunch!
6

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

git status -uno 

1 Comment

git status -uno --porcelain adds nice output for parsing script
5

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 

Comments

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 

3 Comments

But that prints the deleted ones as well.
I add \M git status -uno -sb | grep M\
@kritzel_sw I just modified my command to not display the deleted files.
3

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:

Comments

2

All the answers are great but Git has evolved and now provides an out-of-the-box solution for getting just the name of changed files(includes untracked)

git status --short 

If you need a script-friendly output, use the recommended --porcelain flag

git status --short --porcelain 

Comments

1

To list all modified files use:

git show --stat --oneline HEAD 

Comments

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 

Comments

0

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

Comments

0

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

git log -n1 --oneline --name-status | grep '^M' 

Comments

0

git status --short | grep '^ M'

grep will filter the output to show only lines starting with M, which represent modified files.

Comments

0

git status -uno is much more faster than others when the work dir has many intermediate files for it doesn't scan untracked files at all.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.