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 not getting recent commits

See original GitHub issue

Assume a Github action with two Jobs - job1 & job2

In job1: Use checkout action to checkout the repo, update any file in the repo, commit and push the changes.

In job2:

Again use checkout action. The repo doesn’t contain the commit made in job1.

Here is a replicable sample:

jobs:
  update-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: |  
          // update file1.txt
          git add file1.txt
          git config --local user.email "github-actions@users.noreply.github.com"
          git config --local user.name "github-actions"
          git commit -m "updated file1"
          git push
        
  deploy:
    needs: update-version
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: cat publish file
      run: |
        # the changes made in job1 are not reflected here
         cat file1.txt

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:32
  • Comments:15

github_iconTop GitHub Comments

21reactions
sebastian-muthwillcommented, May 2, 2021

I ran into the same problem and came across this issue. But could figure out a solution within the documentation.

# The branch, tag or SHA to checkout. When checking out the repository that

    # triggered a workflow, this defaults to the reference or SHA for that event.
    # Otherwise, uses the default branch.
    ref: ''

This means by default the commit where the workflow was triggered will be taken. You can specify the master branch with ref: 'master'

16reactions
restfulheadcommented, Nov 11, 2021

As @sebastian-muthwill mentions, you can use the ref attribute to point to a specific branch. This way subsequent jobs always pull the latest code from that branch, and not from the revision that started the workflow.

@mugbug I think fetch-depth: 0 is your friend.

Here’s a full example that works for me when running multiple jobs that each generate a change-log file (i.e. modify the branch)

    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
          ref: main

@adnan-kamili Does this solve your issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

git - How to get back to the latest commit after checking out a ...
If you know the commit you want to return to is the head of some branch, or is tagged, then you can just...
Read more >
Github Actions | Commitsar - aevea
When using JIRA make sure to set actions/checkout@v2 to pull from the pull_request HEAD. Github uses a single merge commit by default which...
Read more >
12. Getting older versions - Git How To
The checkout command can copy any snapshot from the repo to the working directory. 01 Getting hashes for the previous versions. Run: git...
Read more >
2.3 Git Basics - Viewing the Commit History
You can also limit the number of log entries displayed, such as using -2 to show only the last two entries. $ git...
Read more >
7 Github Actions Tricks I Wish I Knew Before I Started
#1: How to Use Github Action Triggers; #2: Reusable Workflows with ... You might not yet be confident enough in the process to...
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