Suppose I have a my-topic-branch
branch that is branched off my local master
branch, and that master
branch is tied to the remote master
branch.
The my-topic-branch
branch was originally created off of a tag called tag1
. tag1
is a tag layed down on the remote master branch, and I see that tag as a result of git fetch
.
Some time passes to allow others to pushed their changes into that remote master branch. And still later, a new tag2
is layed down by someone else (See Update 6 below for the reasons for doing this).
I then use git fetch
again to ensure that I have all of those remote tags into my local repo for further operations.
I rebase to that tag2
like this:
$ git rebase tag2
First, rewinding head to replay your work on top of it...
Applying: CENSORED_LOG_MESSAGE1
Applying: CENSORED_LOG_MESSAGE2
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
But then I run git status
and see this:
$ git status
On branch my-topic-branch
Your branch is ahead of 'tag1' by 195 commits.
(use "git push" to publish your local commits)
My expectation is that the above message should say something about tag2
, and certainly not that I'm ahead of the old tag by 195 commits.
Why would git status
report the commit that my-topic-branch
branched from, and not the new commit that I mostly recently rebased to?
If this is expected behavior, then fine, I will just have to ignore it, but it is odd to see that I'm still behind master
by 195 commits, when that is certainly not true (if the git rebase
actually did what I think it should).
Update 1
I can still find the base point of my-topic-branch
if HEAD is still on that branch, via:
$ git show -s $(git merge-base master @)
commit CENSORED_SHA1_TAG2 (tag: tag2)
Author: CENSORED_AUTHOR
Date: CENSORED_DATE
CENSORED_LOG_MESSAGE_TAG2
$
But this still begs the question about the git status
output.
Update 2:
Update in response to Pesho_T's comment:
I ran git branch -vv
and got the following. This is censored, but adding numbers like "2" and "4" to discriminate them from the others above:
$ git branch -vv | grep my-topic-branch
* my-topic-branch CENSORED_SHA1_TAG1 [tag1: ahead 195] MDFCOR-420 CENSORED_LOG_MESSAGE_TAG1
Update 3:
Replaying some of the commands in torek's answer, I see:
$ git rev-parse --abbrev-ref @{u}
tag1
$ git rev-parse --symbolic-full-name @{u}
refs/tags/tag1
I currently conclude, from torek's very nice writeup, that tag1 is indeed a tag, and not a branch.
Update 4:
I edited prior CENSORED_SHA1's to be consistent:
- CENSORED_SHA1_TAG1 is the commit SHA1 corresponding for tag1
- CENSORED_SHA1_TAG2 is the commit SHA1 corresponding for tag2
Update 5:
Another update in response to torek's answer:
The upstream of a branch is always another branch name or remote-tracking name, as tag names are forbidden
I am not sure of that because of this experiment:
$ git rev-list --count --left-right my-topic-branch...my-topic-branch@{upstream}
195 0
$ git show -s $(git rev-parse my-topic-branch@{u})
commit CENSORED_SHA1_TAG1 (tag: tag1)
Author: CENSORED_AUTHOR
Date: CENSORED_DATE
CENSORED_LOG_MESSAGE_TAG1
The above shows that the upstream is pointing to a tag.
To confirm that both of these tag1 and tag2 tags are on the master branch I did this, per the tips found in answer to Git: How to find out on which branch a tag is?:
$ git branch -a --contains $(git rev-parse tag1^{commit}) | grep -E 'my-topic-branch|master'
* my-topic-branch
master
$
Update 6:
My plans are not actually to git push
back to that the tag (tag2
) I ran git rebase
upon. I am only using that tag as a point on the master
branch to rebase the my-topic-branch
to. The tag2
happens to be a known point, on the master
branch, that the application builds properly upon (I cannot go into further detail on that for confidential reasons). I expect to continue to git rebase
to subsequent tags, tag3
, tag4
and so on, until my-topic-branch
is ready for production, at which time I will merge it back to my local master
branch and do the git push
from there.
Update 7
I posted a MCVE answer to show how the upstream shown by git status
changes once an upstream is set on the parent branch of the topic branch, thus bolstering torek's comments shown therein. I'm still considering torek's answer as the answer to this, because without his input, I would have not figured it out.