Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 211
frbl Avatar asked Feb 04 '20 07:02

frbl


1 Answers

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
...
like image 176
frbl Avatar answered Sep 20 '22 13:09

frbl