ChatGPT解决这个技术问题 Extra ChatGPT

如何将 git 标签合并到分支上

我正在尝试找到将标记提交合并到另一个分支的语法。我猜这很简单,但我微弱的搜索尝试没有找到它。


t
twalberg

你是这个意思?

git checkout destination_branch
git merge tag_name

同样在这里,所以我 git fetch --tags origin 然后我可以: git merge tagname
有没有办法一次合并所有标签?
有没有可能换一种方式?将分支合并到标签?我试过“git checkout tag_name”和“git merge branch”。但最终检查了分支而不是合并。
@learner 一个标签标识一个特定的提交。您无法合并到特定的提交中,因此您需要将标签移动到您想要的提交中。这将解决如何:stackoverflow.com/questions/8044583/…
确保标签在创建后被推送,以便它们在源(远程)的分支中可用,因此其他人可以获取它们: git push origin 如果您过去错过了推送标签,请使用以下方式推送所有标签: git push origin --tags 获取/拉取标签: git fetch[pull] --tag
D
DeadManSpirit

请记住,在合并之前您需要更新标记,它与分支完全不同(git pull origin tag_name 不会更新您的本地标记)。因此,您需要以下命令:

git fetch --tags origin

然后您可以执行 git merge tag_name 将标签合并到一个分支上。


我必须先执行 git remote add upstream git@github.com/org/repo,然后执行 git fetch --tags upstream 才能使其正常工作。
e
e-ruiz

只是补充答案。

合并分支上的最后一个标签:

git checkout my-branch
git merge $(git describe --tags $(git rev-list --tags --max-count=1))

灵感来自 https://gist.github.com/rponte/fdc0724dd984088606b0


p
paiego

这是我发现的唯一全面且可靠的方法。

假设您要将“tag_1.0”合并到“mybranch”中。

    $git checkout tag_1.0 (will create a headless branch)
    $git branch -D tagbranch (make sure this branch doesn't already exist locally)
    $git checkout -b tagbranch
    $git merge -s ours mybranch
    $git commit -am "updated mybranch with tag_1.0"
    $git checkout mybranch
    $git merge tagbranch

F
ForTheWin

我在这里比赛迟到了,但另一种方法可能是:

1) 从标签 ($ git checkout -b [new branch name] [tag name]) 创建一个分支

2)创建一个拉取请求以与您的新分支合并到目标分支


这只会创建不必要的分支。