2

When I use 'git status', it shows me all the modified files. But I wish to see only files with a certain extension (like .py) which I will commit. Is there a way to do this?

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61

5 Answers5

6

If you want to match all files anywhere in the tree that match *.py, then use the following:

git status "*.py"

This ensures that the shell doesn't expand the path and it's interpreted by Git as a pathspec. You can also use single quotes under a Unix shell, but not under Windows.

bk2204
  • 64,793
  • 6
  • 84
  • 100
3

You could run:

git status | grep .py
Evert
  • 93,428
  • 18
  • 118
  • 189
1

For completion, let's not forget the basic -- which has the same behaviour for most git commands.

git status -- *.py

as hinted at by git help status

git status [<options>] [--] <pathspec>...

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
0

Found it on this page, it has a lot of great shortcuts for git tasks.

A little more complicated than the other answers, but it works.

git status -s | grep -o ' \S*YOUR_FILE_TYPE$'

For Python files it would be:

git status -s | grep -o ' \S*py$'

0

If you're scripting this, use the core commands. They're faster, because they don't go gathering and prettifying extra info for human convenience, plus you don't have to scrape the extra bits off to get at what you want.

git diff-index --name-only @ -- \*.py
jthill
  • 55,082
  • 5
  • 77
  • 137