question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

checkout@v2 doesn't allow `git diff origin/master`

See original GitHub issue

Hi, I have such a step in my actions config:

    name: Get list of changed files
    id: changed_files
    run: |
        list=`git diff --name-only origin/master HEAD`
        echo $list
        echo "::set-output name=list::$list"
    shell: bash

When using checkout@v1 it works, while with checkout@v2 I get

fatal: ambiguous argument 'origin/master': unknown revision or path not in the working tree.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:7

github_iconTop GitHub Comments

8reactions
ljharbcommented, Mar 25, 2021

ah sorry, i assumed you were a maintainer.

I don’t think it’s something we can configure; i think it’s something that the checkout action would have to do, by first making a call to the github API, to figure out the requisite fetch depth.

6reactions
JohnStarichcommented, May 1, 2022

This worked for me:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: checkout
      run: |
        commits=${{ github.event.pull_request.commits }}
        if [[ -n "$commits" ]]; then
          # Prepare enough depth for diffs with master
          git fetch --depth="$(( commits + 1 ))"
        fi

For some actions, the diff is a rich source for data analyses. While this works, I’d love a built-in option (or default) to fetch the current PR’s history.

Read more comments on GitHub >

github_iconTop Results From Across the Web

git - master branch and 'origin/master' have diverged, how to ...
I need a fresh copy from the remote instance. git checkout --track origin/master & you're done; now you can delete the placeholder-branch using...
Read more >
Repositories and Branches - Git - user-manual Documentation
The git checkout command normally expects a branch head, but will also accept an arbitrary commit; for example, you can check out the...
Read more >
Don't checkout master locally - Medium
Easy — git already allows you to refer to remote branches directly, via remote tracking branches, like origin/master . Need to do a...
Read more >
Git Diff | Atlassian Git Tutorial
If we execute git diff at this point, there will be no output. This is expected behavior as there are no changes in...
Read more >
Introducing new Git features to Visual Studio 2022
Compare your checked out branch with any local or remote branch. Checkout commit, Checkout the tip commit or any previous commit of remote...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found