Git rev-parse HEAD~2 is not working in GitHub Actions?

Does git rev-parse HEAD~2 work in github actions? we can do git rev-parse HEAD but not the other one. It shows following error even though i have lots of previous commits. Although it runs from the command line/powershell. I have also included my workflow:

Run git rev-parse HEAD~2
git rev-parse HEAD~2
fatal: ambiguous argument ‘HEAD~2’: unknown revision or path not in the working tree.
Use ‘–’ to separate paths from revisions, like this:
‘git […] – […]’
Error: Process completed with exit code 1.

name: Build Windows
on: [ push ]
runs-on: [ self-hosted, Windows ]
- name: Build test
run: git rev-parse HEAD~2

By default actions/checkout fetches only the commit that the ref which triggered the workflow points to. If you want more, you need to use the fetch-depth parameter as described in the README:

1 Like