Yuval Atzmon
Yuval Atzmon

Reputation: 5945

How to get git-status of a single folder in a non-recursive way (not showing its subfolders)

How can I get git-status of a single folder in a non-recursive way?

This is not a duplicate of this question since they address there how to git-status a single folder and it subdirectories, e.g. the accepted answer there is to use git status . which returns a recursive result.

Upvotes: 3

Views: 1606

Answers (2)

anon
anon

Reputation:

The solution is in the definition of pathspec (see man pathspec). It allows non-recursing glob patters and even exclusion patterns and attribute filtering.

In essence: Special paths can be given, that start with a :, and some ”magic signature” before the actual path. There are long and a short form signatures.

For your case, the following works nicely:

git status ':(glob)mypath/*'

This is the long form, :(*)…, where * is a keyword. (glob in this case.) There is no short one for glob.

Note the single quotes, to make git itself glob, and not your shell. (Which may otherwise lead to passing a huge number of arguments to git, if your directory of choice has lot of entries.)

You can also specifically exclude subdirectory contents, by writing:

git status ':^mypath/*/*'

Here we can use the short form :?…, where ? is a key character. (^ in this case.) The long form of :^ is :(exclude).

This variant may have a slightly different meaning. (I have not verified this, but it probably includes changes to the actual subdirectories themselves but not changes to the files inside them.)

Upvotes: 1

CodeWizard
CodeWizard

Reputation: 142342

go into the desired folder and the use:

git status .

This will display the status of the given folder which you are in right now.

Another option is to use:

git ls-files -t -o -m <desired path>

This would display all files changed but not updated (unstaged), or untracked for the given directory.


Non recursive way:

In the desired folder use the combination of git status + grep to filter the results

git status | grep -v /

Upvotes: 0

Related Questions