GIT stage and commit only files with a certain file ending

2.1k views Asked by At

I have tons of modified files, and a good 2/3s of the files are images that I don't care much about, but I still want to commit them. For the rest I need to really look hard at the changes. To minimize the files I need to look at I want to only stage .png and .jpg and .gif files and commit them (cutting down the background noise in order to look at the beef).

Having said that...

How would you stage and commit only files with these file endings without adding each file separately?

Edit:

Files are modified

Directory structure is not flat

I am overwriting a WP Theme that I have highly customized and there is a security update I need to apply

2

There are 2 answers

4
kdopen On BEST ANSWER

Simply

git add \*.jpg \*.png

This will add all tracked and modified files in your repository which match the wildcard pattern

If your image files are the only things under a specific directory

git add <directory>

will add everything under that directory

1
SzG On

Ermmm..., in case of a flat directory structure

git add *.jpg *.gif *.png

Or in a nested directory structure, the trick is to stop the shell from expanding the * symbol, and let git do it. Because git does it recursively for subdirs too.

git add \*.jpg \*.gif \*.png

Or am I missing something?