Git 推 --all vs --mirror

Git push --all vs --mirror

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

我只知道这个:

这是正确的吗?

还有其他区别吗?

正如the documentation中所说:

--all

    Push all branches (i.e. refs under refs/heads/); cannot be used with other <refspec>.

--mirror

    ... specifies that all refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored ...

所以a,如果不是the,关键区别是一个表示refs/heads/*,一个表示refs/*. refs/heads/* 名称是分支名称。 refs/remotes/ 中的任何内容都是 remote-tracking 名称,refs/tags/ 中的任何内容都是标签名称。其他值得注意的 name-spaces 包括 refs/notes/refs/replace/ 和单数 refs/stash.

--mirror选项继续提到:

locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end.

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

始终由 其他 Git 决定是否服从礼貌的请求(没有 --force 的请求)或命令(--force) 对其引用进行更改。

With deleted local branch, --all doesn't push it and --mirror does.

这是 --prune 选项的结果:告诉您的 Git 使用 --prune 意味着 "ask them to delete names in their name-space(s) that are not in mine"。

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

问题是:--all 有时 隐含 ,当您从刚刚克隆的本地存储库 推送 --mirror.
Filippo Valsorda最近的不幸遭遇:

Ok, git, WTF. This is not in the man pages.

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

参见 commit 8e4c8af (02 Sep 2019) by Thomas Gummerer (tgummerer)
(由 Junio C Hamano -- gitster -- in commit fe048e4 合并,2019 年 9 月 30 日)

push: disallow --all and refspecs when remote.<name>.mirror is set

Pushes with --all, or refspecs are disallowed when --mirror is given to 'git push', or when 'remote.<name>.mirror' is set in the config of the repository, because they can have surprising effects.
800a4ab ("push: check for errors earlier", 2018-05-16, Git v2.18.0-rc0) refactored this code to do that check earlier, so we can explicitly check for the presence of flags, instead of their side-effects.

However when 'remote.<name>.mirror' is set in the config, the TRANSPORT_PUSH_MIRROR flag would only be set after we calling 'do_push()', so the checks would miss it entirely.

This leads to surprises for users (see above).

Fix this by making sure we set the flag (if appropriate) before checking for compatibility of the various options.

这导致 Git 2.29(2020 年第 4 季度)代码清理。

参见 commit 842385b, commit 9dad073, commit 26e28fe, commit 75d3bee, commit 20f4b04, commit 5b9427e, commit 8d2aa8d, commit 424e28f, commit e885a84, commit 185e865 (30 Sep 2020) by Jeff King (peff)
(由 Junio C Hamano -- gitster -- in commit 19dd352 合并,2020 年 10 月 5 日)

push: drop unused repo argument to do_push()

Signed-off-by: Jeff King

We stopped using the "repo" argument in 8e4c8af058 ("push: disallow --all and refspecs when remote..mirror is set", 2019-09-02, Git v2.24.0-rc0 -- merge listed in batch #4), which moved the pushremote handling to its caller.