Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does git support wildcards in paths?

Tags:

git

msysgit

I have looked, searched, and read documentation and can't really find anything about this.

Basically, I want to be able to do this:

git reset -- *.exe 

or

git reset -- */some_executable.exe 

Instead of this:

git reset -- some/very/long/path/some_executable.exe 

Also it'd be nice to be able to do this:

git reset -- topleveldirectory/another/subdirectory/* 

Instead of this:

git reset -- topleveldirectory/another/subdirectory/SomeFile.cpp git reset -- topleveldirectory/another/subdirectory/SomFile.h 

I think I can use the wildcard * in git-add to add files, but haven't found anything that works in the case above.

Any suggestions or pointers to where I can look for more info?

Using: git version 1.7.3.1.msysgit.0 on 64-bit Windows 7

like image 885
Nathan McDaniel Avatar asked Feb 16 '11 03:02

Nathan McDaniel


People also ask

What are paths in git?

The pathspec is the mechanism that git uses for limiting the scope of a git command to a subset of the repository. If you have used much git, you have likely used a pathspec whether you know it or not.

What does git reset head do?

The git reset HEAD~2 command moves the current branch backward by two commits, effectively removing the two snapshots we just created from the project history. Remember that this kind of reset should only be used on unpublished commits.


2 Answers

Git does support some pathspec globbing, but you need to be careful to shell-escape the characters so they aren't interpreted by in your case, msys bash, which doesn't support more sophisticated wildcard expansion.

EDIT: Also, for your reset example, you can just pass the directory as an argument to git reset and git will operate recursively.

git reset my/long/path 

rather than

git reset my/long/path/* 
like image 182
Matt Enright Avatar answered Sep 21 '22 12:09

Matt Enright


To reset all exe files recursively from within a git folder, you can do the following:

git reset -- \*.exe 

Or if you would like to add all java files within a specific sub-folder you can do that too, like this:

git add ./some/sub/folder/path/**/*.java 

where ** means all folders recursively from this point in the path

like image 24
Lars Juel Jensen Avatar answered Sep 21 '22 12:09

Lars Juel Jensen