【发布时间】:2018-03-17 23:38:07
【问题描述】:
git push --all 和 git push --mirror 有什么区别?
我只知道这个:
- 删除本地分支后,
--all不会推送它,--mirror会推送。
这是对的吗?
还有其他区别吗?
【问题讨论】:
git push --all 和 git push --mirror 有什么区别?
我只知道这个:
--all 不会推送它,--mirror 会推送。这是对的吗?
还有其他区别吗?
【问题讨论】:
正如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 意味着“要求他们删除其名称空间中不属于我的名称”。
【讨论】:
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 没有识别那个提交,所以我什么都没做。
使用 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 842385b、commit 9dad073、commit 26e28fe、commit 75d3bee、commit 20f4b04、commit 5b9427e、commit 8d2aa8d、commit 424e28f、commit 424e28f、commit e885a84、commit 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处理移至其调用者。
【讨论】: