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.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With