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.

Is there a way to get all commit history for a single branch?

See original GitHub issue

I’m using this action like this (this works splendidly):

- name: Check Out Code
  uses: actions/checkout@v2
  with:
    ref: ${{ env.BRANCH }}
    fetch-depth: 0

I only need to get the entire commit history for just that one ${{ env.BRANCH }}. But using fetch-depth: 0 gets all commit history for all branches and tags, which is unnecessary in my case. Is there a way to get the entire commit history for just the branch referenced in the ref?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:23
  • Comments:9

github_iconTop GitHub Comments

4reactions
solarmosaic-kflorencecommented, Nov 19, 2021

It would probably be better if there was just an action that set up credentials and let users run their own fetches.

3reactions
lourdcommented, Jan 25, 2022

Here’s the job yml for the workaround I just figured out for my use case of running tests and linting on pull requests on my team’s Nx monorepo, in case anyone else finds this later with a similar need:

  lint-and-test:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.pull_request.head.sha }}
      - name: Add PR base ref
        # Fetch the ref of the base branch, just the single commit.
        run: git fetch --depth=1 origin +refs/heads/${{github.base_ref}}:refs/remotes/origin/${{github.base_ref}}
      - name: Track PR base branch
        # Turn the just-fetched ref into a local branch.
        run: git branch --track ${{github.base_ref}} origin/${{github.base_ref}}
      - name: Fetch commits in-between base and HEAD
        # While the ancestor commit between HEAD and the branch base isn't in the local tree
        # fetch X more parent commits of the branch base and branch head.
        run: |
          while [ -z $( git merge-base ${{github.base_ref}} HEAD ) ]; do     
            git fetch --deepen=10 origin ${{github.base_ref}} HEAD;
          done
        # Sets the commit SHAs of head and branch base into two environment variables
        # that `nx affected` will read from.
      - name: Derive SHAs for base and head for `nx affected` commands
        uses: nrwl/nx-set-shas@v2
        with:
          main-branch-name: ${{github.base_ref}}
      - uses: actions/setup-node@v2
        with:
          node-version: 16.x
          cache: yarn
      - name: Install dependencies
        run: yarn install
      - name: Lint
        run: yarn nx affected --target=lint
      - name: Tests
        run: yarn nx affected --target=test
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get commit history for just one branch? - Stack Overflow
This doesn't work if the branch has been merge into master. It only reports history back to the merge point, not all the...
Read more >
2.3 Git Basics - Viewing the Commit History
Viewing the Commit History ; --shortstat. Display only the changed/insertions/deletions line from the --stat command. ; --name-only. Show the list of files ...
Read more >
How to Show Commit History for One Branch Using Git Log ...
To show commit history using Git log with range, move to Git repo, check content list, open file, update and commit it, run...
Read more >
Most common commands to view Git History for Git Commits
How to view Git Commit History of specific intervals? ... All the commits happened since that date comes as the output. It will...
Read more >
How to View Commit History With Git Log - How-To Geek
Git tracks commits over time, allowing you to follow the progression and history of your code. While you can always use Github online...
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