ChatGPT解决这个技术问题 Extra ChatGPT

How do I merge a git tag onto a branch

I'm trying to find the syntax for merging a tagged commit onto another branch. I'm guessing that it's straight forward but my feeble search attempts aren't finding it.


t
twalberg

You mean this?

git checkout destination_branch
git merge tag_name

Same here so I git fetch --tags origin then I could: git merge tagname
Is there a way to merge all tags at once?
Is it possible the other way? Merge a branch to the tag? I tried "git checkout tag_name" and "git merge branch". But ended up checking out the branch instead of merging.
@learner a Tag identifies a specific commit. You can't merge into a specific commit so you'd need to move the tag to the commit you want. This would address the how on that: stackoverflow.com/questions/8044583/…
Ensure that tags are pushed after they are created so that they are available at the origin (remote)'s branch, and therefore others can get them: git push origin If you missed pushing tags in the past, push all using: git push origin --tags To fetch/pull tags: git fetch[pull] --tag
D
DeadManSpirit

Remember before you merge you need to update the tag, it's quite different from branches (git pull origin tag_name won't update your local tags). Thus, you need the following command:

git fetch --tags origin

Then you can perform git merge tag_name to merge the tag onto a branch.


I had to do git remote add upstream git@github.com/org/repo followed by git fetch --tags upstream to make it work.
e
e-ruiz

Just complementing the answer.

Merging the last tag on a branch:

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

Inspired by https://gist.github.com/rponte/fdc0724dd984088606b0


p
paiego

This is the only comprehensive and reliable way I've found to do this.

Assume you want to merge "tag_1.0" into "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

I'm late to the game here, but another approach could be:

1) create a branch from the tag ($ git checkout -b [new branch name] [tag name])

2) create a pull-request to merge with your new branch into the destination branch


This will just create unnecessary branches.