git 将主分支设置为最新标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14054299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set master branch to latest tag
提问by Peter
This is an example of how my git repo is right now:
这是我的 git repo 现在的一个例子:
v1.0 v1.1 v1.2 | | | a - b - c | | master HEAD
v1.0 v1.1 v1.2 | | | a - b - c | | master HEAD
I usually commit, tag and push tags like this:
我通常像这样提交、标记和推送标签:
git commit -a -m "Commit msg"
git tag -a v1.3 -m "Tag msg"
git push --tags
The main problem I have is that the master branch doesn't move to the latest tag, so I'm always in a Detached HEADstate. Is there any way to fix this so the master branch will be always pointing to the latest pushed tag?
我遇到的主要问题是 master 分支没有移动到最新的标签,所以我总是处于Detached HEAD状态。有什么办法可以解决这个问题,让 master 分支总是指向最新的推送标签?
回答by Peter
In this particular case, I had to do the following:
在这种特殊情况下,我必须执行以下操作:
1) First set the master branch to point to the latest tag (where HEAD is pointing), because is the most recent tag. To do so I created a new branch and merged master to it.
1)首先设置master分支指向最新的标签(HEAD指向的地方),因为是最新的标签。为此,我创建了一个新分支并将 master 合并到它。
git branch -b exp
git merge -s ours master
git checkout master
git merge exp
Now master is the same as latest tag:
现在 master 与 latest 标签相同:
v1.0 v1.1 v1.2
| | |
a - b - c
|
HEAD
|
master
2) Once we have master back on place, we need to push both master and tags whenever we do a new commit:
2) 一旦我们将 master 放回原位,每当我们进行新的提交时,我们都需要同时推送 master 和标签:
git commit -a -m "Commit msg"
git tag -a v1.4 -m "Tag msg"
git push master --tags
This way we avoind being in a Detached HEAD mode and master branch is updated.
这样我们就可以避免处于分离的 HEAD 模式并且主分支被更新。
回答by twalberg
Various answers/comments already given about why to not do things this way, but here's how you fix this particular scenario:
已经给出了关于为什么不以这种方式做事的各种答案/评论,但这里是你如何解决这个特定场景:
git checkout -b tmpbranch # creates a branch called tmpbranch at HEAD
git checkout master # switch back to master branch
git merge --ff-only tmpbranch # fast-forward merge master to tmpbranch, fail if not possible
git branch -d tmpbranch # delete tmpbranch, it's not needed anymore
Then, going forward, don't check out a tag, except for this way:
然后,继续,不要签出标签,除了这种方式:
git checkout -b somebranch refs/tags/tagname # creates a new branch starting at tag
That way, you will not be in detached HEAD state, and any new commits will be added starting at the tag in question, which seems to be what you want... After making a commit you can git tag newtag
to create additional tags at the right points.
这样,你就不会处于分离的 HEAD 状态,任何新的提交都会从有问题的标签开始添加,这似乎是你想要的......提交后你可以git tag newtag
在正确的点创建额外的标签.
回答by VonC
A branch doesn't reference a tag.
A tag references a fixedcommit.
分支不引用标签。
标签引用固定提交。
So as long as you git checkout master
, you are not in a detached HEAD mode.
You can then commit and tag: the tag will be created on the LATEST of the current branch.
所以只要你git checkout master
,你就不是处于分离的 HEAD 模式。
然后您可以提交和标记:标记将在当前分支的 LATEST 上创建。
If you were in a detached HEAD mode, see "Git: How can I reconcile detached HEAD
with master/origin
?" for various way of reconciling a detached commit with a branch.
如果您处于分离的 HEAD 模式,请参阅“ Git:如何协调分离HEAD
与master/origin
?”以了解协调分离提交与分支的各种方式。
回答by user128364
Tags are used for creating stable releases. To create a tag for using with the Git Drupal Repository, first, ensure that you're following the tag naming convention if you're using this tag for making a release. From inside the directory of the project, an example is:
标签用于创建稳定版本。要创建用于 Git Drupal 存储库的标签,首先,如果您使用此标签进行发布,请确保遵循标签命名约定。从项目的目录内部,一个例子是:
git tag 7.x-1.0
git tag 7.x-1.0
Once the tag is created, you need to push the tag up to the master repository. By itself, push doesn't send the tags up, you also need to tell it to include the tags in the push by appending the --tags flag:
创建标签后,您需要将标签推送到主存储库。push 本身不会发送标签,您还需要通过附加 --tags 标志告诉它在推送中包含标签:
git push --tags
git push --tags
If you don't want to push all your tags, you can also be specific: Example:
如果您不想推送所有标签,也可以具体说明:例如:
git push origin tag 7.x-1.0
git push origin tag 7.x-1.0
To check and confirm remote tags, the command is : -
要检查和确认远程标签,命令是:-
git tag -l
git tag -l