chr
chr

Reputation: 121

How to exclude some directories from output of git status without having to modify the working tree (e.g. _not_ modifying .gitignore)

In my working tree there's a directory with several modified files that I temporarily would like to not see when I do git status. But this should ideally be done without modifying the "state" of my working tree. How could I do this?

I looked at man git-status but couldn't see an option to exclude a specific directory.

Some workarounds:

If there's no ready made option for git status, then somehow using grep without losing the pretty colours is perhaps what I should be using.

Upvotes: 3

Views: 1497

Answers (3)

Magnuti
Magnuti

Reputation: 165

Duplicate of How to exclude unwanted folders content to be shown when I execute 'git status' command

Use git status . -- ':!dir' to exclude the dir folder when running git status.

Upvotes: 2

David Z
David Z

Reputation: 131550

This might be an appropriate use for git update-index --skip-worktree. To quote from the documentation,

Skip-worktree bit can be defined in one (long) sentence: When reading an entry, if it is marked as skip-worktree, then Git pretends its working directory version is up to date and read the index version instead.

In other words, if you set this flag on a file with git update-index --skip-worktree <filename>, then Git will ignore the actual contents and metadata of the file on disk and will simply pretend it's unmodified. This only applies for read operations; if you run a Git operation that would write to the file (e.g. git checkout or git reset), then Git will give you a warning.

Personally I have this command aliased to git ignore, and the opposite version, git update-index --no-skip-worktree, aliased to git unignore. Of course if you're going to do this, you have to remember that this is entirely unrelated to the mechanism that uses .gitignore files, so you might want to choose a different name if there is any chance of confusion.

Upvotes: 1

Saurabh P Bhandari
Saurabh P Bhandari

Reputation: 6742

Try this

 git -c color.ui=always status | grep -v <dir-to-exclude>

See Colors in Git section here

Git fully supports colored terminal output, which greatly aids in visually parsing command output quickly and easily. A number of options can help you set the coloring to your preference.

color.ui

Git automatically colors most of its output, but there’s a master switch if you don’t like this behavior.

You can also set it to always to ignore the difference between terminals and pipes.

Upvotes: 4

Related Questions