Using git to view all logs associated with a specific file extension in subdirectories

I am trying to see commits in the repository history, but only for files with a specific extension.

If this is a directory structure:

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

And this is the full story:

 $ 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 the logs for a file with the extension .txt:

 $ git log --oneline *.txt f8d4414 1 

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

I also tried:

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

and

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

This works for this case, but it is not practical for more general cases.

and

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

Without success.

+6
source share
1 answer

Try:

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

As far as I can tell, -- used for specifying a path includes subdirectories. Thus, -- '*.txt' searches down all folders from the current directory.

Alternatively, you can limit the results by running a search in a subdirectory, for example. -- 'sub/*.txt' .

+3
source

Source: https://habr.com/ru/post/985234/


All Articles