3

In Git, while adding files to a commit, we can add all files matching a pattern like so:

git add **Component**

I find this feature pretty useful to quickly add lots of files with similar names.

For example, If all my files are named based on components, then I can add all changes I did to a component quickly.

Similarly, is there a way in git to add all files to commit excluding files matching a pattern?

Something like:

git add *.java --exclude **Component1**

So that I can all my java file changes except the changes that I made to the files of component1?

Sumit
  • 2,189
  • 7
  • 32
  • 50
  • that sounds more like something you would solve with bash to call xargs. Something like `blah blah | produce list of files | xargs git add` – eftshift0 May 03 '19 at 21:18
  • Sounds like a job for find. Bash might have a no match glob; zsh almost certainly does – D. Ben Knoble May 03 '19 at 21:31

1 Answers1

11

Try one of

git add *.java ':(exclude):**Component1**'
git add *.java ':!**Component1**'

Any pathspec beginning with a colon is a magic pathspec. exclude is one of them.

j6t
  • 9,150
  • 1
  • 15
  • 35