git push --all --tags: 不兼容

git push --all --tags: incompatible

当我尝试将所有分支和标签推送到远程时,git 发出以下错误:

# git push origin --all --tags
fatal: --all and --tags are incompatible

但是,这有效:

# git push origin refs/heads refs/tags
Everything up-to-date

问题:

  1. 为什么 git 命名为 push-all-branches --all 而不是 --branches--headsgit push origin --all 仅推送分支,而不是所有参考。这种命名背后的哲学是什么?这是否意味着标签真的是 Git 存储库中的第 2-class 公民?

  2. 为什么git不允许同时使用--all--tags


PS。我知道有一个 --follow-tags 选项。我知道有些人不推荐推送所有标签,但本帖与此无关。


man git-push:

--all

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

--tags

All refs under refs/tags are pushed, in addition to refspecs explicitly listed on the command line.

消息“--all and --tags are incompatible”来自builtin/push.c#cmd_push()

这是由 Marek Zawirski in commit b259f09 于 2008 年 8 月引入的 (Git v1.6.1-rc1):

Make push more verbose about illegal combination of options

It may be unclear that --all, --mirror, --tags and/or explicit refspecs are illegal combinations for git push.

Git was silently failing in these cases, while we can complaint more properly about it.

2008 年,Marek implementing git push in JGit, and proposed that patch mentioned above,加入:

I forgot about this one, it was reported long time ago.

It seems that it may be really unclear what's going on with git failing on $ git push --tags --all and similar, as it is implementation related perhaps.

it is possible to configure a remote 与:

[remote "origin"]
  push = refs/heads/*
  push = refs/tags/*

Jeff King discovered a bug(有点僵局)这可能就是这个补丁存在的原因。

The sender does a "tellme-more" and then waits for a line back.
The receiver gets the tellme-more, but never says anything else, presumably because he doesn't have that commit (because master is ahead of any tags).

简而言之,单独推送分支和标签似乎比将它们一起推送更容易支持。

使用“Push git commits & tags simultaneously”、git push --follow-tagsgit config --global push.followTags true 查看更多内容。