首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Github操作,将特定文件夹从一个分支复制到同一个回购中的另一个分支。

Github操作,将特定文件夹从一个分支复制到同一个回购中的另一个分支。
EN

Stack Overflow用户
提问于 2021-10-14 21:25:40
回答 1查看 2.4K关注 0票数 5

是否有允许我复制特定文件夹(.eg )的github操作。在同一私人回购中从一个分支转到另一个分支。我很感谢你的帮助。下面是试图用模仿动作让它发挥作用的方法。

代码语言:javascript
复制
name: Copying static files

on:
  push:
    branches:
      - src # Set a branch name to trigger deployment


jobs:
  copy:
    runs-on: ubuntu-latest
    steps:
    - name: Copycat
      uses: andstor/copycat-action@v3
      with:
        personal_token: ${{ secrets.PERSONAL_TOKEN }}
        src_path: static.
        dst_path: /static/
        dst_owner: CompanyX
        dst_repo_name: MyRepo
        dst_branch: dest
        src_branch: src
        src_wiki: false
        dst_wiki: false
    - name: Copycat2
      uses: andstor/copycat-action@v3
      with:
        personal_token: ${{ secrets.PERSONAL_TOKEN  }}
        src_path: dist.
        dst_path: /dist/
        dst_owner: CompanyX
        dst_repo_name: MyRepo
        dst_branch: des
        src_branch: src
        src_wiki: false
        dst_wiki: false

但我得到了这个错误,即使我有我的个人令牌设置在我的个人资料。

致命:无法读取https://github.com'的密码:没有这样的设备或地址

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-14 23:13:27

如果您想要提交到同一个存储库,您不必指定个人令牌,只需使用actions/checkout@v2 (参见this)

在分支之间复制文件的一个解决方案是使用git checkout [branch] -- $files,请参阅this post

以下工作流将文件从源分支上名为static的目录复制到名为dest的分支

代码语言:javascript
复制
name: Copy folder to other branch

on: [push]

jobs:
  copy:
    name: Copy my folder
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: copy
        env:
          SRC_FOLDER_PATH: 'static'
          TARGET_BRANCH: 'dest'
        run: |
          files=$(find $SRC_FOLDER_PATH -type f) # get the file list
          git config --global user.name 'GitHub Action'
          git config --global user.email 'action@github.com'
          git fetch                         # fetch branches
          git checkout $TARGET_BRANCH       # checkout to your branch
          git checkout ${GITHUB_REF##*/} -- $files # copy files from the source branch
          git add -A
          git diff-index --quiet HEAD ||  git commit -am "deploy files"  # commit to the repository (ignore if no modification)
          git push origin $TARGET_BRANCH # push to remote branch
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69577518

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档