Black
Black

Reputation: 20212

git log - find out which commit added a specific file

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.

Upvotes: 3

Views: 79

Answers (2)

sergej
sergej

Reputation: 17979

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.

Upvotes: 1

phd
phd

Reputation: 94408

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

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

Upvotes: 4

Related Questions