Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git log - find out which commit added a specific file

Tags:

git

I know that we can use the command git show --pretty="" --name-only 90e34953 to list all files from a specific commit.

Is it possible to execute git log and include all files from the commits to the output?

Maybe there is a script which runs through each commit and inserts it into the command above?

e.g. (pseudocode)

$out = "";
foreach($commit in $commits) {
    $out .= $commit
    $out .= "----------------------------------------"
    $out .= (git show --pretty="" --name-only $commit)
}
$out > logfile.txt

We try to find out which commit added a specific file.

like image 572
Black Avatar asked Aug 25 '26 17:08

Black


2 Answers

git log --diff-filter=A -- file

--diff-filter=A filters those commit(s) that add the file.

like image 120
phd Avatar answered Aug 28 '26 08:08

phd


Another option to find out which commit added the file is:

git log --reverse -- <file>

The top most commit is the one that has added the file.

like image 29
sergej Avatar answered Aug 28 '26 07:08

sergej



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!