Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using path wildcards in git log

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'
like image 434
Matt McHenry Avatar asked Mar 22 '12 14:03

Matt McHenry


People also ask

How do you use wildcards in path?

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.

What is pathspec 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. For example, in the command git add README.md , the pathspec is README.md .


3 Answers

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.

like image 72
yoyo Avatar answered Oct 22 '22 21:10

yoyo


use xargs:

find . -name 'Expression.java' | xargs git log --oneline -2
like image 41
Carlos Campderrós Avatar answered Oct 22 '22 22:10

Carlos Campderrós


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.*} 
    
like image 29
VonC Avatar answered Oct 22 '22 20:10

VonC