Hi, list
How can I find out what's the staring reference point (a commit number
or tag name) of a locally created branch? I can use gitk to find out it
but this method is slow, I think there might be a command line to do it
quickly.
Thanks in advance.
--
woody
I can't go back to yesterday - because I was a different person then.
In message <20121224035825.GA17203@zuhnb712>, Woody Wu writes:
How can I find out what's the staring reference point (a commit number
or tag name) of a locally created branch? I can use gitk to find out it
but this method is slow, I think there might be a command line to do it
quickly.
The answer is more complex than you probably suspected.
Technically, `git log --oneline mybranch | tail -n 1` will tell you
the starting point of any branch. But...I'm sure that isn't what you
want to know.
You want to know "what commit was I at when I typed `git branch
mybranch`"? The problem is git doesn't record this information and
doesn't have the slightest clue.
But, you say, I can use `gitk` and see it. See? Right there. That
isn't (necessarily) the "starting point" of the branch, it is the
place where your branch diverged from some other branch. Git is
actually quite able to tell you when the last time your branch
diverged from some other branch. `git merge-base mybranch master`
will tell you this, and is probably the answer you were looking for.
Note that this is the *last* divergence. If your branch diverged and
merged previously that will not be reported. Even worse, if you did a
fast-forward merge (I recommend against them in general) then it is
impossible to discover about what the independent pre-merge history
was really like.
-Seth Robertson
On Mon, Dec 24, 2012 at 11:09 AM, Seth Robertson [off-list ref] wrote:
In message <20121224035825.GA17203@zuhnb712>, Woody Wu writes:
How can I find out what's the staring reference point (a commit number
or tag name) of a locally created branch? I can use gitk to find out it
but this method is slow, I think there might be a command line to do it
quickly.
The answer is more complex than you probably suspected.
Technically, `git log --oneline mybranch | tail -n 1` will tell you
the starting point of any branch. But...I'm sure that isn't what you
want to know.
You want to know "what commit was I at when I typed `git branch
mybranch`"? The problem is git doesn't record this information and
doesn't have the slightest clue.
Maybe we should store this information. reflog is a perfect place for
this, I think. If this information is reliably available, git rebase
can be told to "rebase my whole branch" instead of my choosing the
base commit for it.
--
Duy
From: Tomas Carnecky <hidden> Date: 2016-06-15 22:55:35
On Mon, 24 Dec 2012 12:28:45 +0700, Nguyen Thai Ngoc Duy [off-list ref] wrote:
On Mon, Dec 24, 2012 at 11:09 AM, Seth Robertson [off-list ref] wrote:
quoted
In message <20121224035825.GA17203@zuhnb712>, Woody Wu writes:
How can I find out what's the staring reference point (a commit number
or tag name) of a locally created branch? I can use gitk to find out it
but this method is slow, I think there might be a command line to do it
quickly.
The answer is more complex than you probably suspected.
Technically, `git log --oneline mybranch | tail -n 1` will tell you
the starting point of any branch. But...I'm sure that isn't what you
want to know.
You want to know "what commit was I at when I typed `git branch
mybranch`"? The problem is git doesn't record this information and
doesn't have the slightest clue.
Maybe we should store this information. reflog is a perfect place for
this, I think. If this information is reliably available, git rebase
can be told to "rebase my whole branch" instead of my choosing the
base commit for it.
What's the starting point of the branch if I type: git branch foo <commit-ish>?
On Mon, Dec 24, 2012 at 12:34 PM, Tomas Carnecky
[off-list ref] wrote:
quoted
Maybe we should store this information. reflog is a perfect place for
this, I think. If this information is reliably available, git rebase
can be told to "rebase my whole branch" instead of my choosing the
base commit for it.
What's the starting point of the branch if I type: git branch foo <commit-ish>?
You start working off <commit-ish> so I think the starting point would
be <commit-ish>.
--
Duy
From: Jeff King <hidden> Date: 2016-06-15 22:55:35
On Mon, Dec 24, 2012 at 12:28:45PM +0700, Nguyen Thai Ngoc Duy wrote:
quoted
You want to know "what commit was I at when I typed `git branch
mybranch`"? The problem is git doesn't record this information and
doesn't have the slightest clue.
Maybe we should store this information. reflog is a perfect place for
this, I think. If this information is reliably available, git rebase
can be told to "rebase my whole branch" instead of my choosing the
base commit for it.
Is that what you really want, though? We record the "upstream" branch
already, and you can calculate the merge base with that branch to see
which commits are unique to your branch. In simple cases, that is the
same as "where did I start the branch". In more complex cases, it may
not be (e.g., if you merged some of the early commits in the branch
already). But in that latter case, would you really want to rebase
those commits that had been merged?
The reason that git does not bother storing "where did I start this
branch" is that it is usually not useful. The right question is usually
"what is the merge base". There are exceptions, of course (e.g., if you
are asking something like "what work did I do while checked out on the
'foo' branch"). But for merging and rebasing, I think the computed
merge-base is much more likely to do what people want.
-Peff
On Sun, Dec 23, 2012 at 11:09:58PM -0500, Seth Robertson wrote:
In message <20121224035825.GA17203@zuhnb712>, Woody Wu writes:
How can I find out what's the staring reference point (a commit number
or tag name) of a locally created branch? I can use gitk to find out it
but this method is slow, I think there might be a command line to do it
quickly.
The answer is more complex than you probably suspected.
Technically, `git log --oneline mybranch | tail -n 1` will tell you
the starting point of any branch. But...I'm sure that isn't what you
want to know.
You want to know "what commit was I at when I typed `git branch
mybranch`"?
Yes, this is exactly I want to know.
The problem is git doesn't record this information and
doesn't have the slightest clue.
But, you say, I can use `gitk` and see it. See? Right there. That
isn't (necessarily) the "starting point" of the branch, it is the
place where your branch diverged from some other branch. Git is
actually quite able to tell you when the last time your branch
diverged from some other branch. `git merge-base mybranch master`
will tell you this, and is probably the answer you were looking for.
This is not working to me since I have more than one local branch that
diverged from the master, and in fact, the branch I have in question was
diverged from another local branch. With the method of 'git
merge-base', I have to remember a branch tree in my brain.
But thanks anyway, I see you guys's discussions and it's a little hard
to understand to me at the moment. Currently, I still have to use gitk
with narrowed outputs.
Note that this is the *last* divergence. If your branch diverged and
merged previously that will not be reported. Even worse, if you did a
fast-forward merge (I recommend against them in general) then it is
impossible to discover about what the independent pre-merge history
was really like.
-Seth Robertson
--
woody
I can't go back to yesterday - because I was a different person then.
On Mon, Dec 24, 2012 at 8:31 AM, Woody Wu [off-list ref] wrote:
But thanks anyway, I see you guys's discussions and it's a little hard
to understand to me at the moment. Currently, I still have to use gitk
with narrowed outputs.
Each commit refers to it's parent. If you take a branch, and keep
following the first parent of the commits, you will finally reach the
root commit (the first commit made). You don't see any branches, it's
just one straight line. That's why git can't tell you where a branch
started, because it all looks like a single branch to git.
With merge-base, you basically give git two branches, and git finds
the first ancestor that is common to both branches.
See [1] for an example. If you follow the arrows from branch a, you
get from E to A (note that commit C doesn't know about commit F
pointing to it). So it looks like there is only a single branch.
If you do git merge-base a b, git sees both branches have commit C in
common, and reports that as the merge-base.
[1]: http://g.jk.gs/9W.png
On Mon, Dec 24, 2012 at 1:19 PM, Jeff King [off-list ref] wrote:
On Mon, Dec 24, 2012 at 12:28:45PM +0700, Nguyen Thai Ngoc Duy wrote:
quoted
quoted
You want to know "what commit was I at when I typed `git branch
mybranch`"? The problem is git doesn't record this information and
doesn't have the slightest clue.
Maybe we should store this information. reflog is a perfect place for
this, I think. If this information is reliably available, git rebase
can be told to "rebase my whole branch" instead of my choosing the
base commit for it.
Is that what you really want, though? We record the "upstream" branch
already, and you can calculate the merge base with that branch to see
which commits are unique to your branch. In simple cases, that is the
same as "where did I start the branch". In more complex cases, it may
not be (e.g., if you merged some of the early commits in the branch
already). But in that latter case, would you really want to rebase
those commits that had been merged?
The reason that git does not bother storing "where did I start this
branch" is that it is usually not useful. The right question is usually
"what is the merge base". There are exceptions, of course (e.g., if you
are asking something like "what work did I do while checked out on the
'foo' branch"). But for merging and rebasing, I think the computed
merge-base is much more likely to do what people want.
Rebasing is exactly why I want this. Merge base works most of the time
until you rewrite upstream (which I do sometimes). There are also
cases when I create a branch without upstream, or when upstream is
renamed. Still, making "rebase -i --topic" == "rebase -i $(git
merge-base HEAD @{upstream})" would be cool.
--
Duy
From: Jeff King <hidden> Date: 2016-06-15 22:55:35
On Mon, Dec 24, 2012 at 06:16:05PM +0700, Nguyen Thai Ngoc Duy wrote:
quoted
The reason that git does not bother storing "where did I start this
branch" is that it is usually not useful. The right question is usually
"what is the merge base". There are exceptions, of course (e.g., if you
are asking something like "what work did I do while checked out on the
'foo' branch"). But for merging and rebasing, I think the computed
merge-base is much more likely to do what people want.
Rebasing is exactly why I want this. Merge base works most of the time
until you rewrite upstream (which I do sometimes).
True, although wouldn't you generally want to rebase it on top of the
rewritten upstream in that case (which is what "pull --rebase" will do,
by scanning the reflog for the last version of the upstream that you
actually built on).
There are also cases when I create a branch without upstream, or when
upstream is renamed. Still, making "rebase -i --topic" == "rebase -i
$(git merge-base HEAD @{upstream})" would be cool.
Yeah. I usually just do "rebase -i @{upstream}" which picks the same
commits, but moves to the updated version of upstream (IOW, I both
rewrite and move forward at the same time). But there is value in
rewriting without moving forward in many workflows. That seems like a
sensible feature to me.
-Peff
From: Martin von Zweigbergk <hidden> Date: 2016-06-15 22:55:35
On Sun, Dec 23, 2012 at 11:31 PM, Woody Wu [off-list ref] wrote:
On Sun, Dec 23, 2012 at 11:09:58PM -0500, Seth Robertson wrote:
quoted
In message <20121224035825.GA17203@zuhnb712>, Woody Wu writes:
How can I find out what's the staring reference point (a commit number
or tag name) of a locally created branch? I can use gitk to find out it
but this method is slow, I think there might be a command line to do it
quickly.
The answer is more complex than you probably suspected.
Technically, `git log --oneline mybranch | tail -n 1` will tell you
the starting point of any branch. But...I'm sure that isn't what you
want to know.
You want to know "what commit was I at when I typed `git branch
mybranch`"?
Yes, this is exactly I want to know.
quoted
The problem is git doesn't record this information and
doesn't have the slightest clue.
But, you say, I can use `gitk` and see it. See? Right there. That
isn't (necessarily) the "starting point" of the branch, it is the
place where your branch diverged from some other branch. Git is
actually quite able to tell you when the last time your branch
diverged from some other branch. `git merge-base mybranch master`
will tell you this, and is probably the answer you were looking for.
This is not working to me since I have more than one local branch that
diverged from the master, and in fact, the branch I have in question was
diverged from another local branch.
As Jeff mentions in a later message, "git pull --rebase" would
probably do what you want. It works with local branches too.
I once tried to add the same cleverness that "git pull --rebase"
directly in "git rebase" [1], but there were several issues with those
patches, one of was regarding the performance ("git pull --rebase" can
be equally slow, but since it often involves network, users probably
rarely notice). I think it would be nice to at least add it as an
option to "git rebase" some day. Until then, "git pull --rebase" works
fine.
[1] http://thread.gmane.org/gmane.comp.version-control.git/166710
On Mon, Dec 24, 2012 at 09:24:39AM -0800, Martin von Zweigbergk wrote:
On Sun, Dec 23, 2012 at 11:31 PM, Woody Wu [off-list ref] wrote:
quoted
On Sun, Dec 23, 2012 at 11:09:58PM -0500, Seth Robertson wrote:
quoted
In message <20121224035825.GA17203@zuhnb712>, Woody Wu writes:
How can I find out what's the staring reference point (a commit number
or tag name) of a locally created branch? I can use gitk to find out it
but this method is slow, I think there might be a command line to do it
quickly.
The answer is more complex than you probably suspected.
Technically, `git log --oneline mybranch | tail -n 1` will tell you
the starting point of any branch. But...I'm sure that isn't what you
want to know.
You want to know "what commit was I at when I typed `git branch
mybranch`"?
Yes, this is exactly I want to know.
quoted
The problem is git doesn't record this information and
doesn't have the slightest clue.
But, you say, I can use `gitk` and see it. See? Right there. That
isn't (necessarily) the "starting point" of the branch, it is the
place where your branch diverged from some other branch. Git is
actually quite able to tell you when the last time your branch
diverged from some other branch. `git merge-base mybranch master`
will tell you this, and is probably the answer you were looking for.
This is not working to me since I have more than one local branch that
diverged from the master, and in fact, the branch I have in question was
diverged from another local branch.
As Jeff mentions in a later message, "git pull --rebase" would
probably do what you want. It works with local branches too.
I think what 'git pull --rebase' would do is to fetch from the origin
and do a 'git rebase'. On one hand, I don't understand 'git rebase' so
much from the manual, ont the other hand, I did not get the point why
'git rebase' has something to do with the thing I want to do (what I
want is just query some kind of history information).
I know, my knowledge about git is still so limit. I will keep study from
the man pages.
I once tried to add the same cleverness that "git pull --rebase"
directly in "git rebase" [1], but there were several issues with those
patches, one of was regarding the performance ("git pull --rebase" can
be equally slow, but since it often involves network, users probably
rarely notice). I think it would be nice to at least add it as an
option to "git rebase" some day. Until then, "git pull --rebase" works
fine.
[1] http://thread.gmane.org/gmane.comp.version-control.git/166710
--
woody
I can't go back to yesterday - because I was a different person then.
From: Martin von Zweigbergk <hidden> Date: 2016-06-15 22:55:36
On Thu, Dec 27, 2012 at 9:15 PM, Woody Wu [off-list ref] wrote:
On Mon, Dec 24, 2012 at 09:24:39AM -0800, Martin von Zweigbergk wrote:
quoted
On Sun, Dec 23, 2012 at 11:31 PM, Woody Wu [off-list ref] wrote:
quoted
This is not working to me since I have more than one local branch that
diverged from the master, and in fact, the branch I have in question was
diverged from another local branch.
As Jeff mentions in a later message, "git pull --rebase" would
probably do what you want. It works with local branches too.
I think what 'git pull --rebase' would do is to fetch from the origin
and do a 'git rebase'.
Not if the configured upstream is a local branch (see the
"branch.<name>.*" configuration variables). In that case it will just
rebase the local branch onto the new position of its upstream. If the
upstream is not configured, I believe you can still do "git pull
--rebase . <upstream branch>".
On one hand, I don't understand 'git rebase' so
much from the manual, ont the other hand, I did not get the point why
'git rebase' has something to do with the thing I want to do (what I
want is just query some kind of history information).
I may have misunderstood or assumed things incorrectly that you wanted
to rebase the commits on your branch. So why do you want to know?
(Please ignore me if this was answered elsewhere in the thread that I
might have missed.)
Anyway, to answer your question, you could use a method similar to
what "git pull --rebase" uses internally to figure out the branch
point:
git merge-base $(git rev-parse <branch>) $(git rev-list -g <upstream branch>)
Hope that helps