简体   繁体   中英

Github Actions - Checkout another repo and merge a remote branch - strange behavior

I have a checkout/v3 action that pulls from a remote repository

 - uses: actions/checkout@v3
    with:
      repository: myorg/myrepo
      ref: mybranch
      token: ${{ secrets.ACCESS_TOKEN }}

And then trying to merge in a remote branch

  - run: |
      git config --global user.email "me@myorg.com"
      git config --global user.name "me"
      git fetch
      git merge mybranch origin/${{ env.ANOTHER_BRANCH}}

The first issue I am having is that this fails with an unexpected error

fatal: refusing to merge unrelated histories

These are both branches off of main, with only 1 single letter change test commit made to ANOTHER_BRANCH.

Adding the setting --allow-unrelated-histories takes me past that error, but then I get a merge conflict.

The trouble is this is the only place I get the conflict, so I can't resolve it. If I create a pull request between from ANOTHER_BRANCH -> mybranch there are no reported conflicts. If I pull these branches down locally and do the same merge, there is no conflict. Seems the conflict is related to my GH Action use case.

Any ideas?

GitHub actions use shallow clones by default, as an optimization: there's no point in fetching the whole history if you're not going to use it!

In your use case, however, you are using the history, so you can ask for it with fetch-depth: 0 . That will fetch the full history.

Solution, found in a different question with the same fix:

- uses: actions/checkout@v3
  with:
    fetch-depth: 0

Ref: https://stackoverflow.com/a/71819349/3216427

These are both branches off of main

Make sure with git branch -a --contains main .

They were not .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM