【问题标题】:Git push --all vs --mirrorgit push --all vs --mirror
【发布时间】:2018-03-17 23:38:07
【问题描述】:

git push --allgit push --mirror 有什么区别?

我只知道这个:

  • 删除本地分支后,--all 不会推送它,--mirror 会推送。

这是对的吗?

还有其他区别吗?

【问题讨论】:

    标签: git github push


    【解决方案1】:

    正如the documentation 所说:

    --全部

      推送所有分支(即refs/heads/下的refs);不能使用 与其他 .

    --镜像

      ...指定所有refs/下的refs(包括但不限于refs/heads/refs/remotes/refs/tags/)都被镜像...

    所以a,如果不是the,关键区别在于一个表示refs/heads/*,一个表示refs/*refs/heads/* 名称是分支名称。 refs/remotes/ 中的任何内容都是远程跟踪名称,refs/tags/ 中的任何内容都是标签名称。其他值得注意的命名空间包括 refs/notes/refs/replace/ 和单数 refs/stash

    --mirror 选项继续提到:

    本地更新的引​​用将在远程端强制更新, 并且删除的 refs 将从远程端删除。

    因此--mirror 有效地暗示--force--prune--all 没有。但是,如果您愿意,可以将--force 和/或--prune 添加到git push --all

    始终由 其他 Git 决定是否服从礼貌的请求(那些在没有 --force 的情况下发送的请求)或命令 (--force) 来更改其引用。

    删除本地分支后,--all 不会推送它,--mirror 会推送。

    这是 --prune 选项的结果:告诉您的 Git 使用 --prune 意味着“要求他们删除其名称空间中不属于我的名称”。

    【讨论】:

    • 好的,谢谢@torek。我发布了这个问题,因为我在执行push --all 时出错。问题是我没有使用--force 选项并且文档说Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. This flag disables the check. This can cause the remote repository to lose commits; use it with care. 这是我的情况,因为我已经完成了重置并删除了一些提交。这是正确的吗?
    • 是的。使用git reset 将分支名称“向后”移动通常需要某种强制推送。如果您的 Git 不是太古老,您可以使用“强制租赁”选项以及直接的 --force,它可以让您的 Git 告诉另一个 Git:我相信您的分支名称 B 标识了一些提交 @987654354 @ 如果是这样,则让 B 识别另一个提交。 这个更安全,因为如果你弄错了,他们会拒绝推送错误:我的 B 没有识别那个提交,所以我什么都没做。
    【解决方案2】:

    使用 Git 2.24(2019 年第四季度),您将无法将 git push --all--mirror 一起使用。

    问题是:--all 有时隐含,当您从本地存储库推送时,您刚刚使用--mirror 克隆。
    @987654321 @最近发生了不幸的经历:

    好的,混帐,WTF。这不在手册页中。

    因此,修复早期的回归到“git push --all”,当目标远程存储库设置为镜像时应该禁止该回归。

    参见Thomas Gummerer (tgummerer)commit 8e4c8af(2019 年 9 月 2 日)。
    (由 Junio C Hamano -- gitster -- 合并于 commit fe048e4,2019 年 9 月 30 日)

    push:禁止 --all 并在设置 remote.<name>.mirror 时引用规范

    使用 --all 推送,或者当 --mirror 被赋予 'git push' 或在存储库的配置中设置 'remote.<name>.mirror' 时,不允许使用 refspecs,因为它们可能会产生令人惊讶的效果。
    800a4ab ("push: check for errors early", 2018-05-16, Git v2.18.0-rc0) 重构了此代码以更早地进行检查,因此我们可以显式检查标志的存在,而不是它们的副作用。

    但是,如果在配置中设置了“remote.<name>.mirror”,则只有在我们调用“do_push()”之后才会设置TRANSPORT_PUSH_MIRROR 标志,因此检查会完全忽略它。

    这会给用户带来惊喜(见上文)。

    通过确保在检查各种选项的兼容性之前设置标志(如果合适)来解决此问题。

    这导致使用 Git 2.29(2020 年第四季度)进行代码清理。

    commit 842385bcommit 9dad073commit 26e28fecommit 75d3beecommit 20f4b04commit 5b9427ecommit 8d2aa8dcommit 424e28fcommit 424e28fcommit e885a84commit 185e865@(30) 987654338@.
    (由 Junio C Hamano -- gitster -- 合并于 commit 19dd352,2020 年 10 月 5 日)

    push:将未使用的 repo 参数放到 do_push()

    签字人:杰夫·金

    我们停止在8e4c8af058 中使用“repo”参数(“push: disallow --all and refspecs when remote..mirror is set”, 2019-09-02, Git v2.24.0-rc0 -- merge 列在 batch #4) 中,这将 pushremote 处理移至其调用者。

    【讨论】:

      猜你喜欢
      • 2012-02-29
      • 2018-05-26
      • 2011-04-29
      • 2019-02-11
      • 2020-03-25
      • 1970-01-01
      • 1970-01-01
      • 2016-08-06
      • 2020-07-30
      相关资源
      最近更新 更多