8

While doing a release, I checked out the previously released tag and cherry-picked the new items (using git cherry-pick <commit-id>) into it. Then, I created a new tag using git tag <tag-name>.

Will this affect the old tag I cherry-picked the changes into?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
Stranger
  • 10,332
  • 18
  • 78
  • 115

2 Answers2

9

In one word: no. Tags, once created, are not meant to move around like branch references do. You'd need to deliberately use

git tag --force v1.0 <some-other-commit>

to move the v1.0 tag to some other commit. Cherry-picking other commits (in other words, applying the changes introduced by those other commits) on top of a tagged commit won't affect the tag.

As an example, if v1.0 is a tag and your history looks as follows,

A -- B [master,v1.0]
 \
  C -- D [develop]

and then you run

git checkout v1.0
git checkout -b rc1.1
git cherry-pick C
git cherry-pick D

you'll end up with

A -- B [master,v1.0]
 \    \
  \    C' -- D' [HEAD,rc1.1]  
   \
    C -- D [develop]

The v1.0 tag will stay in place, still pointing at commit B.

jub0bs
  • 60,866
  • 25
  • 183
  • 186
2

When you cherry-pick a commit, Git is essentially creating a patch from that commit (finding out what kind of changes it introduced) and applies that to the current HEAD. In that process, a completely new commit is created without any link back to the original commit you cherry-picked from. Git will just copy the commit message and commit author and reuse it in the new commit; but apart from that, it’s a completely separate commit.

As such, it’s no different to creating a new commit yourself. So no, cherry-picking, like committing anything, will not affect other commits or tags.

poke
  • 369,085
  • 72
  • 557
  • 602