Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commit uses regular expressions or globs?

Tags:

git

regex

glob

Is it possible to use regular expressions in, e.g., git commit ".*my_file.*" ?

I tried, and it seems to only interpret these as globs. I also tired a regex flag:

git commit -regex ".*my_file.*"`

Throws an error.

Does anyone know of a way to combine regular expressions with Git commands?

like image 392
makansij Avatar asked Sep 14 '25 12:09

makansij


2 Answers

Not with Git itself. Git just receives a list of files passed from the shell, so it would be up to your shell to do regular expression matching for files. I do not think bash can do this, but other shells may be able to.

like image 142
mipadi Avatar answered Sep 16 '25 03:09

mipadi


The best way I can think of to do this is using the find command. For example, if you want only python files:

find -type f -regex ".*\.py$" -exec git commit {} -m "committing only and all python files" \;

Can anyone else think of something less unwieldy?

like image 31
makansij Avatar answered Sep 16 '25 01:09

makansij