Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get git-status of a single subfolder?

Tags:

git

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?

like image 580
EoghanM Avatar asked Jun 25 '09 15:06

EoghanM


People also ask

How do I track a folder in git?

Create an empty . gitignore file inside the empty folder that you would like to commit. Git will only track Files and the changes in them. So folders are tracked as part of the file changes in them.

What is status command in git?

The git status command displays the state of the working directory and the staging area. It lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git. Status output does not show you any information regarding the committed project history.

What is a subdirectory git?

git. Git uses this special subdirectory to store all the information about the project, including all files and sub-directories located within the project's directory. If we ever delete the . git subdirectory, we will lose the project's history. Next, we will change the default branch to be called main .

Does git add include subdirectories?

It will add all the Folders , Subfolders and files to the existing repo.


1 Answers

git status . 

will show the status of the current directory and subdirectories.

For instance, given files (numbers) in this tree:

a/1 a/2 b/3 b/4 b/c/5 b/c/6 

from subdirectory "b", git status shows new files in the whole tree:

% git status # On branch master # # Initial commit # # Changes to be committed: #   (use "git rm --cached <file>..." to unstage) # #   new file:   ../a/1 #   new file:   ../a/2 #   new file:   3 #   new file:   4 #   new file:   c/5 #   new file:   c/6 # 

but git status . just shows files in "b" and below.

% git status . # On branch master # # Initial commit # # Changes to be committed: #   (use "git rm --cached <file>..." to unstage) # #   new file:   3 #   new file:   4 #   new file:   c/5 #   new file:   c/6 # 

Just this subdirectory, not below

git status . shows all files below "b" recursively. To show just the files in the "b" but not below, you need to pass a list of just the files (and not directories) to git status. This is a bit fiddly, depending on your shell.

Zsh

In zsh you can select ordinary files with the "glob qualifier" (.). For example:

% git status *(.) On branch master  Initial commit  Changes to be committed:   (use "git rm --cached <file>..." to unstage)          new file:   3         new file:   4 

Bash

Bash doesn't have glob qualifiers but you can use GNU find to select ordinary files and then pass them along to git status like so:

bash-3.2$ find . -type f -maxdepth 1 -exec git status {} + On branch master  Initial commit  Changes to be committed:   (use "git rm --cached <file>..." to unstage)          new file:   3         new file:   4 

This uses -maxdepth which is a GNU find extension. POSIX find doesn't have -maxdepth, but you can do this:

bash-3.2$ find . -path '*/*' -prune -type f -exec git status {} + On branch master  Initial commit  Changes to be committed:   (use "git rm --cached <file>..." to unstage)          new file:   3         new file:   4 
like image 177
Matt Curtis Avatar answered Sep 21 '22 15:09

Matt Curtis