HEAD^ may not exist
Closed this issue · 1 comments
For repositories created from a template (though certainly possible for others, too), HEAD^
is not a valid revision after the initial commit. Thus, the current default of HEAD^
as the base revision for comparison is undefined, and the action terminates with a failure. For example,
+ git rev-parse HEAD^
fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
.git
HEAD^
In such cases, only the current revision (i.e., HEAD
) should be examined since it has no parent.
Of course, this issue only manifests when this action is executed for the push
GitHub event when the action is defined in the initial commit.
There doesn't appear to be a flag for git diff
to show the changes introduced by the initial commit. As a workaround, the commit of the "empty tree" can be used as the parent:
git diff --color $(echo -n | git hash-object -t tree --stdin)..HEAD
where
echo -n | git hash-object -t tree --stdin
calculates the SHA-1 hash of the "empty tree" in Git.
Courtesy of Stack Overflow: How to get Git diff of the first commit?.