10

Suppose I have a list of files (newline delimited) in a file, and I want to git add all these files.

Is there some way to do this directly?

I have checked online and looked at git help add, but did not see anything that helps.

merlin2011
  • 71,677
  • 44
  • 195
  • 329
  • @BrianRoach, I agree it is a more specific case of the other question, but when I was trying to solve this problem, the first thing that comes to mind is not to Google for "command line arguments from a file content". Therefore I think this question will still be beneficial for future seekers. – merlin2011 Mar 21 '14 at 21:18
  • Do this: https://stackoverflow.com/questions/4227994/how-do-i-use-the-lines-of-a-file-as-arguments-of-a-command/4229346#4229346. But, replace `some_command $line` with `git add $line`. – Gabriel Staples Feb 18 '20 at 08:01
  • Cancel that; use this answer instead! https://stackoverflow.com/questions/4227994/how-do-i-use-the-lines-of-a-file-as-arguments-of-a-command/60276836#60276836 – Gabriel Staples Feb 18 '20 at 08:45

1 Answers1

8

You can use xargs:

xargs -a file -d '\n' git add
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • 1
    doesn't work for me because it takes my file content as one string. I use https://stackoverflow.com/a/4228046/6614155 … ```git add `cat my-file-list` ``` my-file-list contains list on only one line. – bcag2 May 09 '23 at 08:13