5

I want to see the diff between a file between two commits on Github Actions. Here is my main.yml file:

name: GitHub Actions Test
on: [push]
jobs:
  Test-GitHub-Actions:
    runs-on: ubuntu-latest
    steps:
      - name: Adding actions/checkout@v2
        uses: actions/checkout@v2
      - name: Git diff
        run: git diff 7100c3bbc34a9667ca9034a8ec321677ed4b5828 4c5952b60b8a5911154534ea1fefec3567c49c52 ${{ github.workspace }}/data.xml
      - name: Run Python
        run: |
          python3 ${{ github.workspace }}/.github/workflows/app.py
      - name: Setup git - step 1
        run: git config --global user.email "[email protected]"
      - name: Setup git - step 2
        run: git config --global user.name "Adith Raghav"
      - name: Check for changes
        run: git status
      - name: Stage changed files
        run: git add .
      - name: Commit changed files
        run: git commit -m "auto updating history.json and maybe checked for changes in data"
      - name: fetch from main 
        run: git fetch origin main
      - name: Push to main
        run: git push origin HEAD:main

I get the following error on Github Actions:

fatal: bad object 7100c3bbc34a9667ca9034a8ec321677ed4b5828
Error: Process completed with exit code 128.

I do not know what this is supposed to mean. It works perfectly on my local. Do you know how to fix it?

9
  • Maybe your local repository has the object 64252781112f8d3c890d930c2c074fbc6509da96 but the repository on GitHub does not.
    – mkrieger1
    Commented Feb 21, 2022 at 10:29
  • At which step does this error occur exactly?
    – mkrieger1
    Commented Feb 21, 2022 at 10:31
  • At the step called "Git diff"
    – Robo
    Commented Feb 21, 2022 at 10:33
  • @mkrieger1, I'm not sure I understand. Both are in the same repo.
    – Robo
    Commented Feb 21, 2022 at 10:33
  • Are you sure the error is not "fatal: bad object 7100c3bbc34a9667ca9034a8ec321677ed4b5828"?
    – mkrieger1
    Commented Feb 21, 2022 at 10:34

2 Answers 2

5

Set fetch-depth to 0 in checkout action.

- name: Adding actions/checkout@v2
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

See here for details.

-3

Never1 use a raw hash ID in a GitHub Action.

Be aware that checkout@v2 makes a shallow clone. A shallow clone is one that omits various Git objects on purpose so as to clone faster. Such a clone cannot be used for most Git purposes; it's mainly good for compiling code (e.g., in a Jenkins or other builder). Probably, this particular action would have worked for one-time usage had you used the v1 checkout, or set the depth.

While this is sort of a Git issue, it's mainly a problem in that you've written a useless GitHub Action. See GitHub's articles on writing proper GitHub Actions to figure out how to write one that doesn't break like this. There's not really much else to be said here, other than "don't use raw hash IDs" and "know about shallow clones" and the "depth" parameter for the checkout@v2 action.


1Insert G&S HMS-Pinafore routine as usual.

4
  • The Action isn't useless; this reproduces the same error as the one I'm using for my code.
    – Robo
    Commented Feb 21, 2022 at 11:23
  • What can I use instead of a raw hash ID?
    – Robo
    Commented Feb 21, 2022 at 11:27
  • Generally, instead of a raw hash ID you'd have a name: a branch name like refs/heads/somebranch, a tag name like refs/tags/v1.2, a remote-tracking name, or some other name. In some cases, you'll start with a name and then manipulate it to find a merge base or other related hash ID. So you'd get a full (or sufficiently deep) clone and use git merge-base incoming base (add refs/heads/ as needed). For git diff, note that the three-dot syntax id-A...id-B will automatically find the (or a) merge base between the two IDs (given as names or hash IDs) and diff that against the second.
    – torek
    Commented Feb 21, 2022 at 11:34
  • 1
    @mkrieger1: Gilbert & Sullivan. There's a famous song in it ("I am the captain of the Pinafore ...") that has a whole "what never? no never!" bit in it.
    – torek
    Commented Feb 21, 2022 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.