Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git rebase and keep tags update [duplicate]

Tags:

git

git-rebase

This is my git log

commit beba35
aaa

commit 2d34d4
bbb(tag: ATag)

commit be2f8a
cccc

If I use git rebase and change be2f8a, then I will get a new git log

commit as2sd2e
aaa

commit sdf2sdf
bbb

commit be2f8a
cccc

We know, sdf2sdf and 2d34d4 are same commits even if they have different commit id. But the tag will stay on 2d34d4 and will not update to sdf2sdf.

Is the any way to keep tag follow new commit when I use git rebase?

like image 236
bytefish Avatar asked Feb 23 '26 16:02

bytefish


2 Answers

There is no straightforward way to tell git to "move that tag along with the rebase".

You have to do it by hand :

  • spot the new target commit
  • (like @padawin suggested) move the tag to this commit git tag -f ATag sdf2sdf
like image 129
LeGEC Avatar answered Feb 26 '26 10:02

LeGEC


Tags are more to mark something fixed in time (a release for example). However, if you want to use tags, you can use git tag -f tagName commitHash manually to update it.

This being said, maybe you would want to use a branch instead of a tag. Branches are more flexible in term of being "moved around". Say you have the following:

commit beba35 (yourBranch)
aaa

commit 2d34d4 (yourBranchTag)
bbb

commit be2f8a
cccc

(masterBranch)

Instead of rebasing yourBranch on top of masterBranch, you can rebase yourBranchTag on top of masterBranch and then rebase yourBranch on top of yourBranchTag.

You end up having to maintain them in the order, but they would all stay in the same ancestors line.

Having this yourBranchTag branch does not mean that you will keep it or merge it, maybe it is just to keep a "bookmark" in your log. Once you are done with yourBranch and it's ready to be merged in masterBranch, you can then ditch yourBranchTag.

like image 27
padawin Avatar answered Feb 26 '26 08:02

padawin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!