tags:

views:

53

answers:

4

I have very nested directories in a project, and I'm a lazy programmer.

Let's say I have a file name EventEditor.foo I want to stage my file regardless of whether it's in the root directory or ./src/holy/sweet/mother/of/baby/raptor/jesus/this/is/a/long/hiearchy/EventEditor.foo

My goal would be to be all, "Yo Git, add EventEditor" and bam. It stages it with me only having to type something like git add *EventEdi*. Is this possible? Or am I day dreaming?

Much <3. Thanks if you spend any time answering :)

+7  A: 

If you would like to match a glob recursively when using git add, start the glob you pass in to git add with a directory name (such as . for the current directory), and make sure that the glob is in quotes so that Git can interpret it instead of the shell:

git add "./*EventEdi*"

A full example:

$ git init git-add
Initialized empty Git repository in /Users/lambda/tmp/stackoverflow/git-add/.git/
$ cd git-add/
$ mkdir -p foo/bar/baz
$ touch foo/bar/baz/some-long-filename.txt
$ git add "./*long-filename*"
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached ..." to unstage)
#
#   new file:   foo/bar/baz/some-long-filename.txt
#

From the manual:

Fileglobs (e.g. *.c) can be given to add all matching files. Also a leading directory name (e.g. dir to add dir/file1 and dir/file2) can be given to add all files in the directory, recursively.

Brian Campbell
No, this didn't work at all. Git (1.7.1) accepts the add, does not give me any messages saying it did not find any files with that 'pathspec', and prints nothing to stdo. Normally I get something like `fatal: pathspec '<my pattern>' did not match any files`
Jonathan Dumaine
@Jonathan If you get nothing printed to stdout, that probably means that it worked. `git add`, like many Unix commands, prints nothing upon success. Check `git status` to see if the file has been added.
Brian Campbell
Nope. Doesn't work. Screenshot of the commands I used: http://imgur.com/1aIvO.png
Jonathan Dumaine
+1  A: 

Brian's answer is pretty shifty ;) But you may also find useful:

git add -i

or

gitg
takeshin
Yes interactive mode is 'okay' but it requires you to find the file you're looking for and then associate with a random number (not to mention having to do separate sub-modes for `[u]pdate` and `[a]dd untracked`. If I already know the file name I'm looking for, and it is unique, it would be much easier to type a partial blob of the file name.
Jonathan Dumaine
Also, I do from time to time use gitx.
Jonathan Dumaine
A: 

Brian's answer directly addresses your need, but I'll note that if /very/deeply/nested/file/with-obscenely-long_and_tortured_name is already being tracked by Git, and you've just changed it, then you can say git add -u to stage those changes. If there are other changes that you wish not to stage, that could be git add -up to let you decide piecewise.

Novelocrat
+1  A: 

If you're on Linux, you can easily use something like :

find . -name EventEditor.foo -exec git add {} \;
Matthieu
This works very nice as an alias.
takeshin