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?
The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area. We also say that they will be staged.
Stage all Files The -A option is shorthand for --all . Another way to do this would be to omit the -A option and just specify a period to indicate all files in the current working directory: $ git add . Note: The command git add .
In the Commit window, select the file you want to partially commit, then select the text you want to commit in the right pane, then right-click on the selection and choose 'Stage selected lines' from the context menu.
That's where Git's add command comes in. We add files to a staging area, and then we commit what has been staged. Even the deletion of a file must be tracked in Git's history, so deleted files must also be staged and then committed.
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 adddir/file1
anddir/file2
) can be given to add all files in the directory, recursively.
If you're on Linux, you can easily use something like :
find . -name EventEditor.foo -exec git add {} \;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With