Search code examples
gitgit-commitgit-taggit-squash

What happens to tags of squashed commits?


If I have commit A tagged with tag e.g. tag-A, and then the next commit B tagged with tag-B; if I squash these 2 commits what happens to the tags? Will both be assigned to the squashed commit?


Solution

  • The tags won't move because a rebase rewrites history. The original commits will have the tags since tags don't move. Here's a picture:

    Before:

    (HEAD) B - tag-B
           |
           A - tag-A
           |
           X
    

    After:

             B - tag-B
             |
    (HEAD) C A - tag-A
           |/
           X
    

    Here C is the squash of A and B. It starts a completely new history, in which A and B will not participate. The branch head will move over to C and will proceed from there.