推git提交&同时标记 [英] Push git commits & tags simultaneously

查看:82
本文介绍了推git提交&同时标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到 git push --tags 是一个单独的操作,它对普通的旧的 git push 。推送标签应该是有意识的选择,因为您不想意外推送标签。没关系。但是有没有办法将两者联系在一起? (除了 git push&& git push --tags 。)

解决方案

2015年5月更新



截至 git 2.4.1 ,你可以这样做:

  git config --global push.followTags true 




如果设置为true,默认启用--follow-tags选项。您可以在推送时通过指定--no-follow-tags来覆盖此配置。




2013年4月更新



由于 git 1.8.3(2013年4月22日)您不必再执行2个命令来推送分支,然后推送标签


新的 - follow-tags 选项告诉 git push to 推送分支时推送相关的注释标签

现在您可以尝试,推送新提交时:

  git push --follow-tags 

虽然不会全部推送所有本地标签,只有通过 Git 2.4.1+(2015年第二季度)将推出 push.followTags



c $ c>:参见如何让< git push 在分支中包含标签?



原始答案,2010年9月



核选项是 git push --mirror ,它会将下的所有ref都推送出去。



您也可以只推送一个标签与您当前的分支提交:

  git push origin:v1.0.0 

您可以将 - tags 选项与refspec结合使用,如:

  git push origin --tags:

(因为 - tags 表示:所有在 refs / tags 下的ref都被推送, 除了在命令行中明确列出的refspecs之外)




您也有此条目推送分支和标签


一个方便的提示只发布到 Git邮件列表ZoltánFüzesi:



我使用 .git / config 来解决这个问题:



  [remote来源] 
url = ...
fetch = + refs / heads / *:refs / remotes / origin / *
push = + refs / heads / *
push = + refs / tags / *




添加 git push origin 会上传你的所有分支和标签。如果你只想上传其中的一部分,你可以枚举它们。



还没有尝试过,但看起来它可能有用,直到其他方式推送分支和标签的同时被添加到git push。

另一方面,我不介意输入:



  $ git push&& git push --tags 

当心,如评论 Aseem Kishore


$ b

push = + refs / heads / * will 强行推动所有分支机构


这只是我刚刚的,所以仅供参考。







RenéScheibe 这个有趣的评论


- follow-tags 参数具有误导性,因为只有 .git / refs下的标签/ tags 被考虑。

如果运行 git gc ,标签将从 .git / refs / tags .git / packed-refs 。之后 git push --follow-tags ... 无法按预期工作。



I'm aware of the reason that git push --tags is a separate operation to plain old git push. Pushing tags should be a conscious choice since you don't want accidentally push one. That's fine. But is there a way to push both together? (Aside from git push && git push --tags.)

解决方案

Update May 2015

As of git 2.4.1, you can do

git config --global push.followTags true

If set to true enable --follow-tags option by default. You may override this configuration at time of push by specifying --no-follow-tags.

Update April 2013

Since git 1.8.3 (April 22d, 2013), you no longer have to do 2 commands to push branches, and then to push tags:

The new "--follow-tags" option tells "git push" to push relevant annotated tags when pushing branches out.

You can now try, when pushing new commits:

git push --follow-tags

That won't push all the local tags though, only the one referenced by commits which are pushed with the git push.

Git 2.4.1+ (Q2 2015) will introduce the option push.followTags: see "How to make "git push" include tags within a branch?".

Original answer, September 2010

The nuclear option would be git push --mirror, which will push all refs under refs/.

You can also push just one tag with your current branch commit:

git push origin : v1.0.0 

You can combine the --tags option with a refspec like:

git push origin --tags :

(since --tags means: All refs under refs/tags are pushed, in addition to refspecs explicitly listed on the command line)


You also have this entry "Pushing branches and tags with a single "git push" invocation"

A handy tip was just posted to the Git mailing list by Zoltán Füzesi:

I use .git/config to solve this:

[remote "origin"]
    url = ...
    fetch = +refs/heads/*:refs/remotes/origin/*
    push = +refs/heads/*
    push = +refs/tags/*

With these lines added git push origin will upload all your branches and tags. If you want to upload only some of them, you can enumerate them.

Haven't tried it myself yet, but it looks like it might be useful until some other way of pushing branches and tags at the same time is added to git push.
On the other hand, I don't mind typing:

$ git push && git push --tags

Beware, as commented by Aseem Kishore

push = +refs/heads/* will force-pushes all your branches.

This bit me just now, so FYI.


René Scheibe adds this interesting comment:

The --follow-tags parameter is misleading as only tags under .git/refs/tags are considered.
If git gc is run, tags are moved from .git/refs/tags to .git/packed-refs. Afterwards git push --follow-tags ... does not work as expected anymore.

这篇关于推git提交&amp;同时标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆