1

For example I have lots of unstaged files.

How could I only commit unstaged python files (.py)?

Enze Chi
  • 1,733
  • 17
  • 28

1 Answers1

2

If you look at the gitignore synax, ** will dig down into sub directories. So the following should work to get all the python files added.

git add **/*.py
Cohan
  • 4,384
  • 2
  • 22
  • 40
  • 3
    Without quotes, you're letting your shell do the expansion, not Git. `git add **/*.py` will work if your shell manages `**` (zsh, and bash if you activated extglob). This works for any command, not just Git, since your shell is doing the job. To have Git do the wildcard management, you need to quote it like `git add '**/*.py'`. – Matthieu Moy Jul 13 '15 at 07:49
  • The `add` command would stage the untracked files too. That's not what I want. I one want to stage or commit the tracked and modified files. – Enze Chi Jul 14 '15 at 23:55
  • 2
    Changing git add **/*.py to git add '**/*.py' forked for me. Thanks @MatthieuMoy – Kavi Sek Apr 11 '21 at 04:12