【问题标题】:Is there a difference in git worktrees on linux and windows runners on githublinux上的git worktrees和github上的windows runners有区别吗
【发布时间】:2022-06-30 23:19:48
【问题描述】:

我有一个 github 操作,它创建一个工作树,将文件复制到其中,然后将其推送到一个分支(与操作所在的分支不同的分支)。

当使用ubuntu-latest 时,效果很好。

git worktree add -B ghpages html_build origin/ghpages
cp -a docs/. html_build/

cd html_build

git add . 
git commit -m "ghpages"
git push 

使用windows-2019 时,尝试推送到当前分支而不是工作树会失败。

git worktree add -B ghpages html_build origin/ghpages
robocopy .\docs\ .\html_build\ /MIR

cd html_build

git add . 
git commit -m "ghpages"
git push 

动作中的错误是:

remote: error: GH006: Protected branch update failed for refs/heads/main.        
remote: error: At least 1 approving review is required by reviewers with write access.        
To https://github.com/XXX/XX
 ! [remote rejected]   main -> main (protected branch hook declined)
error: failed to push some refs to 'https://github.com/XXX/XX'

所以在 linux 上它正确地推送到 ghpages 分支,在 Windows 上它似乎尝试推送到我已保护的 main 分支。当我删除保护时,它实际上只是在推动它(而不是 ghpages)。

【问题讨论】:

  • 根据docs.microsoft.com/en-us/windows-server/administration/…/mir 是“等同于 /e 加 /purge”,所以这会破坏 .git 文件。这使得 in 中的所有文件成为主存储库的 html_build 目录的一部分,这反过来又解释了一切。你可能想要/e,而不是/mir
  • @torek 哇。这令人沮丧。你能回答一下吗,我可以接受
  • 我不“做”窗户,所以我没有测试过,但如果你有,我会把它变成答案。

标签: git github


【解决方案1】:

Windows 或 Linux 设置上的各种 Git 命令之间应该没有显着差异,除了操作系统带来的任何限制(例如,Windows 机器将无法签出文件 con.py 和 @ 987654323@)。但是比较这两个脚本,我发现了一件事:

cp -a docs/. html_build/

[对]

robocopy .\docs\ .\html_build\ /MIR

不知道robocopy 可能会做什么,我去了https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy,这反过来告诉我/mir 是“镜子”的缩写,这意味着/purge。这将删除一个.git 文件,如git worktree add 放置到添加的工作树中。反过来,这使得它不再是一个添加的工作树,而只是常规工作目录的一部分——并且单独的分支也消失了。

切换到/e(而不是/mir)应该可以解决问题。

【讨论】:

    猜你喜欢
    • 2019-01-14
    • 1970-01-01
    • 2016-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多