git status -> Show files that will be added (staged) in subdirectories

GitVersion Control

Git Problem Overview


Say I start a git repository in a folder, and I have several subdirectories in it.

I have several globbing patterns .gitignore to exclude files in the subdirectories. However, when I do git status before I stage anything, git status only shows the names of the subfolders that will be added, without being specific about which files in each subdirectory will be added (staged) if I do git add ..

Interestingly though, git status is explicit about the files that will be committed after I stage files with git add ..

Is there anyway to ask git status to be explicit about files for the files that would be staged?

Git Solutions


Solution 1 - Git

Try:

git status -u

or the long form:

git status --untracked-files

which will show individual files in untracked directories.

Here's the detailed description of -u option from git-status man page:

> -u[<mode>]
> --untracked-files[=<mode>] > > Show untracked files. > > The mode parameter is optional (defaults to all), and is used to specify the handling of untracked files; when -u is not used, the default is normal, i.e. show untracked files and directories. > > The possible options are: > > * no - Show no untracked files > * normal - Shows untracked files and directories > * all - Also shows individual files in untracked directories. > > The default can be changed using the status.showUntrackedFiles configuration variable documented in git-config(1).

Solution 2 - Git

You can simply use

git add --dry-run .

in the root of your repository which gives you a list of any file in any sub directory that would be added while considering .gitignore.

Solution 3 - Git

>git ls-files -o --exclude-standard

Every path in your worktree that isn't staged (-o) and won't be ignored by git add (--exclude-standard).

Solution 4 - Git

How about putting a .gitignore file in your sub directories instead along the line of

# Ignore everything in this directory
*
# Except these file
!.gitignore
!file1
!file2
!file3

Solution 5 - Git

There is a huge chance it is due to line ending. Solution:

git config --global core.autocrlf true

But don't just run this command, validate before executing it. Use git diff, if most of the files show no difference, it is due to line ending. Use it well.

Solution 6 - Git

use git command git ls-files -o to list untracked file

instead -o use -c --cached Show cached files in the output (default)

-d --deleted Show deleted files in the output

-m --modified Show modified files in the output

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAmelio Vazquez-ReinaView Question on Stackoverflow
Solution 1 - GitPenghe GengView Answer on Stackoverflow
Solution 2 - GitcweigelView Answer on Stackoverflow
Solution 3 - GitjthillView Answer on Stackoverflow
Solution 4 - GitAdrian CornishView Answer on Stackoverflow
Solution 5 - GitMaifee Ul AsadView Answer on Stackoverflow
Solution 6 - GitPradeep PandeyView Answer on Stackoverflow