Reputation: 7154
When programming in java it is common to have file structures as deep as
com/company/project/folder/subfolder
So when adding a file you have to type
git add com/company/project/folder/subfolder/SomeAwesomeClass.java
Is there a faster way? like some sort of git add-if-matches SomeAwesomeClass.java
Upvotes: 4
Views: 815
Reputation: 2881
Try the following command:
git add *AwesomeClass.java
But this will add all files with that name under the current directory or any of its subdirectories as deep as possible.
If you want to add only a specific file inside a specific directory you can try:
git add *subfolder/SomeAwesomeClass.java
You can also try the following to add all files on a specific directory:
git add *subfolder/*
Note that there is no spaces before or after the asterisk symbol.
I have tried these on Mac OS X with the same exact scenario and it worked.
Upvotes: 2
Reputation: 7154
Ok, so I just cooked up a little recipe. A simple bash function that you can add to you .bash_profile
function add(){
git add $(git status --porcelain | grep "$1" | cut -c 4-)
}
To use it you can just call add something
and it will add any files that match, so if you have 2 files:
com/company/project/folder/subfoler/AwesomeClass.java
com/company/project/folder/subfoler/subfolder/CoolClass.java
You can call
add Awesome
And it will add the AwesomeClass.java
Upvotes: 0
Reputation: 1430
If you intend to add the whole subdirectory, then you can simply git add the directory
git add com
If you really only want to add that one class, then the easiest solution is to do the Unix thing and compose commands together. In this case, the find
command is the thing which is really good at finding files with a given name. You can pass the output of find to git in bash by surrounding the find command with $()
git add $(find . -name SomeAwesomeClass.java)
Upvotes: 2
Reputation: 8938
You can just type git add com
unless there are other files in the directory structure that you don't want to add..
Upvotes: 1