Kuba Suder
Kuba Suder

Reputation: 7827

Git status - is there a way to show changes only in a specific directory?

I would like to see a list of files modified since the last commit, as git status shows, but I care only about files located in a single directory. Is there a way to do this? I tried git status <directory>, but it seems this does something completely different (lists all changed files, as they would be if I wrote git add <directory> first).

The documentation for git-status doesn't tell much, apart from the fact that it accepts the same options that git-commit does (but git-commit's purpose isn't to show lists of changed files).

Upvotes: 186

Views: 135201

Answers (5)

avs
avs

Reputation: 65

To get git status of a different directory:

git -C <directory_path> status

From the Documentation:

-C <path>: Run as if git was started in <path> instead of the current working directory.

Upvotes: 4

Sam Doidge
Sam Doidge

Reputation: 2828

From within the directory:

git status .

You can use any path really, use this syntax:

git status <directoryPath>

For instance for directory with path "my/cool/path/here"

git status my/cool/path/here

Upvotes: 260

Kerem
Kerem

Reputation: 11586

As a note, if you simplify to check git stats without going to git directory;

### create file
sudo nano /usr/local/bin/gitstat

### put this in

#!/usr/bin/env bash

dir=$1

if [[ $dir == "" ]]; then
    echo "Directory is required!"
    exit
fi

echo "Git stat for '$dir'."

git --git-dir=$dir/.git --work-tree=$dir diff --stat

### give exec perm
sudo chmod +x /usr/local/bin/gitstat

And calling that simple script: gitstat /path/to/foo-project. You can also use it while in foo-project just doing gitstat . and so suppose shorter than git status -s, git diff --stat or git diff --stat HEAD if your are always using console instead of gui's.

Credits:

Upvotes: 2

CB Bailey
CB Bailey

Reputation: 793329

The reason that git status takes the same options as git commit is that the purpose of git status is to show what would happen if you committed with the same options as you passed to git status. In this respect git status is really git commit --preview.

To get what you want, you could do this which shows staged changes:

git diff --stat --cached -- <directory_of_interest>

and this, which shows unstaged changes:

git diff --stat -- <directory_of_interest>

or this which shows both:

git diff --stat HEAD -- <directory_of_interest>

Upvotes: 36

Can Berk G&#252;der
Can Berk G&#252;der

Reputation: 113400

Simplest solution:

  1. Go to the directory
  2. git status | grep -v '\.\.\/'

Of course this discards colors.

Upvotes: 14

Related Questions