I have a file down deep in my git tree:
$ git ls-files | grep /Expression.java
sm/src/main/java/cl/utilities/sm/Expression.java
I'd like to get a log of its activity without having to type the whole path. Basically I want this output:
$ git log --oneline -2 sm/src/main/java/cl/utilities/sm/Expression.java
2718cdc cleaned up some warnings
f30cf15 Added missing @Overrides
... but without having to type sm/src/main/java/cl/utilities/sm
. I tried lots of things, but none of them worked:
$ git log -- \*/Expression.java
$ git log -- \*Expression.java
$ git log -- \*\*/Expression.java
$ git log -- '*/Expression.java'
$ git log -- '**/Expression.java'
You can use the wildcard (*) sign to indicate a single component between two forward slashes in a base path. Do NOT use wildcards to indicate the following: One or more forward slashes.
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. For example, in the command git add README.md , the pathspec is README.md .
Use a wildcard, no escapes or quotes required:
git log -- */Expression.java
Tested on Windows 7 in cmd shell and git bash.
Depending on your shell, you may need quotes -- if single quotes don't work, try double quotes.
use xargs
:
find . -name 'Expression.java' | xargs git log --oneline -2
With git 2.8 (March 2016), wildcards are more firmly supported both as pathspec or refspec.
See commit aac4fac, commit df714f8, commit 1cc777d (10 Feb 2016) by Jeff King (peff
).
(Merged by Junio C Hamano -- gitster
-- in commit e6a6a76, 24 Feb 2016)
That means that:
wilcard works with pathspecs:
git log -- "*.t"
# or
git log "*.t"
wildcard works with refspecs (when searching for a commit message starting with 'b
' for instance):
git log "HEAD^{/b.*}" --
# or
git log "HEAD^{/b.*}
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