鱼C论坛

 找回密码
 立即注册
查看: 2726|回复: 1

[已解决]github actions里用actions/checkout和github-push时,怎么忽略某个文件夹?

[复制链接]
发表于 2023-2-23 16:32:56 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
github actions里用actions/checkout和github-push时,怎么忽略某个文件夹?

code下有
.github/workflows
dir1
dir2
file1
file2


actions里checkout时,怎么忽略dir2?
push回去时,怎么才能不覆盖dir2?
最佳答案
2023-4-12 18:45:10
在使用 actions/checkout action 时,可以通过指定 ignore 参数来忽略某些文件或文件夹。具体的做法是在 with 参数中添加一个 ignore 字段,其中列出要忽略的文件或文件夹名称。
例如,如果要忽略 dir2 文件夹,可以这样做:
- name: Checkout Repo
  uses: actions/checkout@v2
  with:
    ignore: |
      dir2

要在 push 操作中排除某些文件或文件夹,可以借助于 Git 的 .gitignore 文件。在 .gitignore 文件中列出要忽略的路径即可。然后在 push 操作中,使用 git add --force 命令来确保要提交的文件不包括被忽略的文件。
具体地,可以这样做:
- name: Push changes
  run: |
    git config --global user.email "you@example.com"
    git config --global user.name "Your Name"
    git add --all
    git add --force !dir2/
    git commit -m "Commit message"
    git push

注意,这里使用了一个特殊的语法 !dir2/,表示排除 dir2 文件夹及其子目录。如果要排除某个文件,可以使用 !file1。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-4-12 18:45:10 | 显示全部楼层    本楼为最佳答案   
在使用 actions/checkout action 时,可以通过指定 ignore 参数来忽略某些文件或文件夹。具体的做法是在 with 参数中添加一个 ignore 字段,其中列出要忽略的文件或文件夹名称。
例如,如果要忽略 dir2 文件夹,可以这样做:
- name: Checkout Repo
  uses: actions/checkout@v2
  with:
    ignore: |
      dir2

要在 push 操作中排除某些文件或文件夹,可以借助于 Git 的 .gitignore 文件。在 .gitignore 文件中列出要忽略的路径即可。然后在 push 操作中,使用 git add --force 命令来确保要提交的文件不包括被忽略的文件。
具体地,可以这样做:
- name: Push changes
  run: |
    git config --global user.email "you@example.com"
    git config --global user.name "Your Name"
    git add --all
    git add --force !dir2/
    git commit -m "Commit message"
    git push

注意,这里使用了一个特殊的语法 !dir2/,表示排除 dir2 文件夹及其子目录。如果要排除某个文件,可以使用 !file1。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-23 19:27

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表