Is there a way to just commit one file type extension from a folder?

Victor R. Oliveira picture Victor R. Oliveira · Oct 31, 2014 · Viewed 16.4k times · Source

I have a folder with a lot of stuff and I would like just to commit ".c" extension files. Is there a command to do this or do I need to add each file name manually?

Answer

Sergey Zaharchenko picture Sergey Zaharchenko · Apr 4, 2018

For me, just git add *.c didn't work. I encountered fatal error like this:

git add *.php
The following paths are ignored by one of your .gitignore files:
wp-config.php
Use -f if you really want to add them.
fatal: no files added

So, in this variant git tried to add ignored files.

But such variant:

git add \*.php

worked flawlessly. By the way, you can do git diff the same way:

git diff -- \*.php