frbl
frbl

Reputation: 1292

Git diff gives me a fatal: bad revision 'HEAD~1'

I'm trying to check which files have changed previously in a github action. For this I'm running the following command:

git diff --name-only HEAD~1 -- .'

While this works locally, on github actions I seem to get this error:

fatal: bad revision 'HEAD~1'
Checking if any files changed

I'm using the https://github.com/actions/checkout action for doing the checkout.

Upvotes: 12

Views: 5671

Answers (1)

frbl
frbl

Reputation: 1292

So I managed to solve it. Apparently the action package I used seems to only fetch the last commit, hence giving the error where it cannot find the other commits when I look for them. The fix was to actually fetch more than one version, this is what I'm doing now in my action, and it works:

...
steps:
 - name: Checkout code
   uses: actions/checkout@v2
   with:
     fetch-depth: 5
...

Upvotes: 18

Related Questions