The two commands I have found handy for dealing with this situation are git ls-files and xargs.
If you run the command:
git ls-files -oIt will show you all of the untracked files in your working directory, one file per line. A problem that you will run into here is that it also shows files in your .gitignore. To get around this issue, you just need another argument to specify your .gitignore:
git ls-files -o --exclude-per-directory=.gitignoreNow that you have all of the files you want to add, you just need to run git add on all of them. This is where xargs comes in handy. It will read from standard in, break it up on line endings and then feed each line as an argument into another command. Putting it all together, you get:
git ls-files -o --exclude-per-directory=.gitignore | xargs git addThat last command will add any untracked files to your git repository. The beautiful thing here is that we can also leverage some UNIX-y goodness if we want to as well. Let's say we're working on a project and we only want to commit some XSLT we have been working on. You can do this by throwing grep into the command chain:
git ls-files -o --exclude-per-directory=.gitignore | grep xslt | xargs git addThis will only add files that contain "xslt" in their names. This same approach comes in handy when you remove files from your working copy but forget to run git rm.


10 comments:
You can add something like this to the .gitconfig in your home dir as an alias:
gadd = !sh -c 'git ls-files -o --exclude-per-directory=.gitignore | grep "$0" | xargs git add'
so you can do:
git gadd xslt
出遊不拘名勝,有景就是好的 ..................................................
I do like ur article~!!!...................................................
感謝分享--每天都要快樂喔................................
很用心的blog,推推哦 ........................................
謝謝您的分享~感恩唷!!..................................................
要像鐵鎚和釘子一樣,永遠向著定點努力。..................................................
nice to know you ~........................................
The persistence behind a bill is ratify is up to date regarding the pinched out and easier said than done wait horizontal under a understanding that provide a stanch path to citizenship term papers writing!!!
Magnificent! To tell the certainty this is a kind post concerning this topic. I got an unpolluted solution from here. Also I can refer to you all hwsolvers.com/programming_project here to get educational helps. However will wait for more posts from the blogger. Thanks a lot…….
Post a Comment