The task in these cases is to use, instead of oldrev, the commit that is the root of the new branch, which is the commit reachable from newrev but not from any of the other heads. Although there are a number of suggestions as to how to get this, I have found what I think is a simpler solution. In Perl, I use
if($oldrev eq "0000000000000000000000000000000000000000"){$oldrev now references the parent of the earliest commit reachable from the new head only (git rev-list lists commit objects in reverse chronological order). Then, one can use
$oldrev = `git rev-list $newrev --not --branches | tail -n 1`;
$oldrev =~ s/\s$//;
$oldrev .= "^";
}
my @filestocheck = split(/\s/,to get the list of files modified by the push.
`git diff $oldrev..$newrev --name-only --no-color`
);