How to get git-status of a single subfolder?

Viewed 35808

When I do git status in a subfolder of my repository it includes the status of parent folders also.

Is there a way to constrain git-status to just a particular folder?

7 Answers

It is possible to restrict git status to the current directory (without child folders) by giving a pathspec using the magic word glob and *::

git status ':(glob)*'

Imperfect, but this works as well from within the the directory you are interested in:

git status | grep -v ' \.\./'

That will hide all directories that would require an upward reference in their relative path.

If you want to get color spitting out the other end, set color.status to always:

git config color.status always

For me this worked:

git status -uall

Some plumbing commands do take a directory as parameter:

git ls-files -t -o -m aDirectory

would give you all files changed but not updated (not added to stage), or untracked. And that for a directory.

As written in this thread, git ls-files does not support a '--added option.

more fundamental reason is because ls-files plumbing is about the index.
Added is not about comparison between the index and the work tree.
It is between the HEAD commit and the index, and it does not belong to ls-files plumbing.

So, using commands mentioned here:

git diff-index --name-only -B -R -M -C HEAD src

would give you both non-added and added files

git diff-files --name-only -B -R -M -C src

would give you only non-added files. (while detecting rewrites, renames, copies, ...)

As usual with plumbing commands, some scripting is in order ;)

When I tried git, I didn't find a way to do that.

I ended up doing:

x@x:~/x$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       b
#       main/a
nothing added to commit but untracked files present (use "git add" to track)

x@x:~/x$ git status | grep main
#       main/a
Related