Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using git to see all logs related to a specific file extension within subdirectories

Tags:

git

git-log

I am trying to see the commits in the history of a repository but just for files with an specific extension.

If this is the directory structure:

$ tree
.
├── a.txt
├── b
└── subdir
    ├── c.txt
    └── d

And this is the full history:

$ git log --name-only --oneline 
a166980 4
subdir/d
1a1eec6 3
subdir/c.txt
bc6a027 2
b
f8d4414 1
a.txt

If I want to see logs for file with .txt extension:

$ git log --oneline *.txt
f8d4414 1

It returns only the file that is in the current directory, not in subdirectories. I want to include all possible subdirectories inside the current directory.

I've also tried:

$ git log --oneline */*.txt
1a1eec6 3

And:

$ git log --oneline *.txt */*.txt
1a1eec6 3
f8d4414 1

That works for this case, but it is not practical for more generic cases.

And:

$ git log --oneline HEAD -- *.txt
f8d4414 1

Without success.

like image 497
hector Avatar asked Apr 16 '15 04:04

hector


People also ask

Which git command is used to view the history of all the changes to a file?

Using git log --follow -p bar will show the file's entire history, including any changes to the file when it was known as foo .

How do you find all commits to a file in git?

Use git log --all <filename> to view the commits influencing <filename> in all branches.

How do I view files in git log?

To find out which files changed in a given commit, use the git log --raw command. It's the fastest and simplest way to get insight into which files a commit affects.


1 Answers

Try:

git log --oneline -- '*.txt' 

The -- is used to indicate only positional arguments will follow. And '*.txt' searches all folders from the current directory on down.

Alternatively, you could limit the results by starting the search in a subdirectory, e.g. -- 'sub/*.txt'.

like image 121
sfletche Avatar answered Sep 25 '22 03:09

sfletche