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?
There is no straightforward way to tell git to "move that tag along with the rebase".
You have to do it by hand :
git tag -f ATag sdf2sdfTags 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With