{"thread":{"id":"32451","subject":"Find the starting point of a local branch","startedAt":"2012-12-24T03:58:25Z","lastAt":"2012-12-28T06:38:25Z","messageCount":17,"participants":["Woody Wu","Seth Robertson","Nguyen Thai Ngoc Duy","Tomas Carnecky","Jeff King","Junio C Hamano","Kevin","Martin von Zweigbergk"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"205455","messageId":"20121224035825.GA17203@zuhnb712","threadId":"32451","inReplyTo":null,"subject":"Find the starting point of a local branch","fromName":"Woody Wu","fromEmail":"narkewoody@gmail.com","sentAt":"2012-12-24T03:58:25Z","receivedAt":"2012-12-24T03:58:25Z","isPatch":false,"sender":{"key":"narkewoody@gmail.com","avatar":null},"body":"Hi, list\n\nHow can I find out what's the staring reference point (a commit number\nor tag name) of a locally created branch? I can use gitk to find out it\nbut this method is slow, I think there might be a command line to do it\nquickly.\n\nThanks in advance.\n-- \nwoody\nI can't go back to yesterday - because I was a different person then.\n"},{"id":"205456","messageId":"201212240409.qBO49wkV020768@no.baka.org","threadId":"32451","inReplyTo":"20121224035825.GA17203@zuhnb712","subject":"Re: Find the starting point of a local branch","fromName":"Seth Robertson","fromEmail":"in-gitvger@baka.org","sentAt":"2012-12-24T04:09:58Z","receivedAt":"2012-12-24T04:09:58Z","isPatch":false,"sender":{"key":"in-gitvger@baka.org","avatar":null},"body":"\nIn message <20121224035825.GA17203@zuhnb712>, Woody Wu writes:\n\n    How can I find out what's the staring reference point (a commit number\n    or tag name) of a locally created branch? I can use gitk to find out it\n    but this method is slow, I think there might be a command line to do it\n    quickly.\n\nThe answer is more complex than you probably suspected.\n\nTechnically, `git log --oneline mybranch | tail -n 1` will tell you\nthe starting point of any branch.  But...I'm sure that isn't what you\nwant to know.\n\nYou want to know \"what commit was I at when I typed `git branch\nmybranch`\"?  The problem is git doesn't record this information and\ndoesn't have the slightest clue.\n\nBut, you say, I can use `gitk` and see it.  See?  Right there.  That\nisn't (necessarily) the \"starting point\" of the branch, it is the\nplace where your branch diverged from some other branch.  Git is\nactually quite able to tell you when the last time your branch\ndiverged from some other branch.  `git merge-base mybranch master`\nwill tell you this, and is probably the answer you were looking for.\nNote that this is the *last* divergence.  If your branch diverged and\nmerged previously that will not be reported.  Even worse, if you did a\nfast-forward merge (I recommend against them in general) then it is\nimpossible to discover about what the independent pre-merge history\nwas really like.\n\n\t\t\t\t\t-Seth Robertson\n"},{"id":"205459","messageId":"CACsJy8CNd3W_WUMbZ1QZ4ReZ5ziX90QejK9mh1TMs0ig33kGMw@mail.gmail.com","threadId":"32451","inReplyTo":"201212240409.qBO49wkV020768@no.baka.org","subject":"Re: Find the starting point of a local branch","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2012-12-24T05:28:45Z","receivedAt":"2012-12-24T05:28:45Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Dec 24, 2012 at 11:09 AM, Seth Robertson <in-gitvger@baka.org> wrote:\n>\n> In message <20121224035825.GA17203@zuhnb712>, Woody Wu writes:\n>\n>     How can I find out what's the staring reference point (a commit number\n>     or tag name) of a locally created branch? I can use gitk to find out it\n>     but this method is slow, I think there might be a command line to do it\n>     quickly.\n>\n> The answer is more complex than you probably suspected.\n>\n> Technically, `git log --oneline mybranch | tail -n 1` will tell you\n> the starting point of any branch.  But...I'm sure that isn't what you\n> want to know.\n>\n> You want to know \"what commit was I at when I typed `git branch\n> mybranch`\"?  The problem is git doesn't record this information and\n> doesn't have the slightest clue.\n\nMaybe we should store this information. reflog is a perfect place for\nthis, I think. If this information is reliably available, git rebase\ncan be told to \"rebase my whole branch\" instead of my choosing the\nbase commit for it.\n-- \nDuy\n"},{"id":"205460","messageId":"1356327291-ner-6552@calvin","threadId":"32451","inReplyTo":"CACsJy8CNd3W_WUMbZ1QZ4ReZ5ziX90QejK9mh1TMs0ig33kGMw@mail.gmail.com","subject":"Re: Find the starting point of a local branch","fromName":"Tomas Carnecky","fromEmail":"tomas.carnecky@gmail.com","sentAt":"2012-12-24T05:34:51Z","receivedAt":"2012-12-24T05:34:51Z","isPatch":false,"sender":{"key":"tomas.carnecky@gmail.com","avatar":null},"body":"On Mon, 24 Dec 2012 12:28:45 +0700, Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:\n> On Mon, Dec 24, 2012 at 11:09 AM, Seth Robertson <in-gitvger@baka.org> wrote:\n> >\n> > In message <20121224035825.GA17203@zuhnb712>, Woody Wu writes:\n> >\n> >     How can I find out what's the staring reference point (a commit number\n> >     or tag name) of a locally created branch? I can use gitk to find out it\n> >     but this method is slow, I think there might be a command line to do it\n> >     quickly.\n> >\n> > The answer is more complex than you probably suspected.\n> >\n> > Technically, `git log --oneline mybranch | tail -n 1` will tell you\n> > the starting point of any branch.  But...I'm sure that isn't what you\n> > want to know.\n> >\n> > You want to know \"what commit was I at when I typed `git branch\n> > mybranch`\"?  The problem is git doesn't record this information and\n> > doesn't have the slightest clue.\n> \n> Maybe we should store this information. reflog is a perfect place for\n> this, I think. If this information is reliably available, git rebase\n> can be told to \"rebase my whole branch\" instead of my choosing the\n> base commit for it.\n\nWhat's the starting point of the branch if I type: git branch foo <commit-ish>?\n"},{"id":"205461","messageId":"CACsJy8DkA-J+ds1eHBqrRyiZrOigORTtxVeEQpZjGHrBR+QjCQ@mail.gmail.com","threadId":"32451","inReplyTo":"1356327291-ner-6552@calvin","subject":"Re: Find the starting point of a local branch","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2012-12-24T05:45:21Z","receivedAt":"2012-12-24T05:45:21Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Dec 24, 2012 at 12:34 PM, Tomas Carnecky\n<tomas.carnecky@gmail.com> wrote:\n>> Maybe we should store this information. reflog is a perfect place for\n>> this, I think. If this information is reliably available, git rebase\n>> can be told to \"rebase my whole branch\" instead of my choosing the\n>> base commit for it.\n>\n> What's the starting point of the branch if I type: git branch foo <commit-ish>?\n\nYou start working off <commit-ish> so I think the starting point would\nbe <commit-ish>.\n-- \nDuy\n"},{"id":"205462","messageId":"20121224061938.GA25186@sigill.intra.peff.net","threadId":"32451","inReplyTo":"CACsJy8CNd3W_WUMbZ1QZ4ReZ5ziX90QejK9mh1TMs0ig33kGMw@mail.gmail.com","subject":"Re: Find the starting point of a local branch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2012-12-24T06:19:38Z","receivedAt":"2012-12-24T06:19:38Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Dec 24, 2012 at 12:28:45PM +0700, Nguyen Thai Ngoc Duy wrote:\n\n> > You want to know \"what commit was I at when I typed `git branch\n> > mybranch`\"?  The problem is git doesn't record this information and\n> > doesn't have the slightest clue.\n> \n> Maybe we should store this information. reflog is a perfect place for\n> this, I think. If this information is reliably available, git rebase\n> can be told to \"rebase my whole branch\" instead of my choosing the\n> base commit for it.\n\nIs that what you really want, though? We record the \"upstream\" branch\nalready, and you can calculate the merge base with that branch to see\nwhich commits are unique to your branch. In simple cases, that is the\nsame as \"where did I start the branch\". In more complex cases, it may\nnot be (e.g., if you merged some of the early commits in the branch\nalready).  But in that latter case, would you really want to rebase\nthose commits that had been merged?\n\nThe reason that git does not bother storing \"where did I start this\nbranch\" is that it is usually not useful. The right question is usually\n\"what is the merge base\". There are exceptions, of course (e.g., if you\nare asking something like \"what work did I do while checked out on the\n'foo' branch\"). But for merging and rebasing, I think the computed\nmerge-base is much more likely to do what people want.\n\n-Peff\n"},{"id":"205463","messageId":"7vmwx4newy.fsf@alter.siamese.dyndns.org","threadId":"32451","inReplyTo":"CACsJy8DkA-J+ds1eHBqrRyiZrOigORTtxVeEQpZjGHrBR+QjCQ@mail.gmail.com","subject":"Re: Find the starting point of a local branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-24T06:27:09Z","receivedAt":"2012-12-24T06:27:09Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:\n\n> On Mon, Dec 24, 2012 at 12:34 PM, Tomas Carnecky\n> <tomas.carnecky@gmail.com> wrote:\n>>> Maybe we should store this information. reflog is a perfect place for\n>>> this, I think. If this information is reliably available, git rebase\n>>> can be told to \"rebase my whole branch\" instead of my choosing the\n>>> base commit for it.\n>>\n>> What's the starting point of the branch if I type: git branch foo <commit-ish>?\n>\n> You start working off <commit-ish> so I think the starting point would\n> be <commit-ish>.\n\nYeah, that sounds sensible.  Don't we already have it in the reflog,\nthough?\n\nWhat is trickier is when you later transplant it to some other base\n(perhaps prepare a topic on 'master', realize it should better apply\nto 'maint' and move it there).  If the user did the transplanting by\nhand, reflog would probably not have enough information, e.g. after\n\n    $ git checkout maint^0\n    $ git log --oneline master..topic\n    $ git cherry-pick $one_of_the_commit_names_you_see_in_the_above\n    $ git cherry-pick $another_commit_name_you_see_in_the_above\n      ...\n    $ git branch -f topic\n\nno reflog other than HEAD@{} will tell you that you were at maint^0,\nso the reflog of topic wouldn't know it \"forked\" from there, either.\n"},{"id":"205465","messageId":"20121224073103.GA10793@zuhnb712","threadId":"32451","inReplyTo":"201212240409.qBO49wkV020768@no.baka.org","subject":"Re: Find the starting point of a local branch","fromName":"Woody Wu","fromEmail":"narkewoody@gmail.com","sentAt":"2012-12-24T07:31:04Z","receivedAt":"2012-12-24T07:31:04Z","isPatch":false,"sender":{"key":"narkewoody@gmail.com","avatar":null},"body":"On Sun, Dec 23, 2012 at 11:09:58PM -0500, Seth Robertson wrote:\n> \n> In message <20121224035825.GA17203@zuhnb712>, Woody Wu writes:\n> \n>     How can I find out what's the staring reference point (a commit number\n>     or tag name) of a locally created branch? I can use gitk to find out it\n>     but this method is slow, I think there might be a command line to do it\n>     quickly.\n> \n> The answer is more complex than you probably suspected.\n> \n> Technically, `git log --oneline mybranch | tail -n 1` will tell you\n> the starting point of any branch.  But...I'm sure that isn't what you\n> want to know.\n> \n> You want to know \"what commit was I at when I typed `git branch\n> mybranch`\"?  \n\nYes, this is exactly I want to know.\n\n>The problem is git doesn't record this information and\n> doesn't have the slightest clue.\n> \n> But, you say, I can use `gitk` and see it.  See?  Right there.  That\n> isn't (necessarily) the \"starting point\" of the branch, it is the\n> place where your branch diverged from some other branch.  Git is\n> actually quite able to tell you when the last time your branch\n> diverged from some other branch.  `git merge-base mybranch master`\n> will tell you this, and is probably the answer you were looking for.\n\nThis is not working to me since I have more than one local branch that\ndiverged from the master, and in fact, the branch I have in question was\ndiverged from another local branch.  With the method of 'git\nmerge-base', I have to remember a branch tree in my brain.\n\nBut thanks anyway, I see you guys's discussions and it's a little hard\nto understand to me at the moment. Currently, I still have to use gitk\nwith narrowed outputs.\n\n\n> Note that this is the *last* divergence.  If your branch diverged and\n> merged previously that will not be reported.  Even worse, if you did a\n> fast-forward merge (I recommend against them in general) then it is\n> impossible to discover about what the independent pre-merge history\n> was really like.\n> \n> \t\t\t\t\t-Seth Robertson\n\n-- \nwoody\nI can't go back to yesterday - because I was a different person then.\n"},{"id":"205466","messageId":"CAO54GHDPaBqLGV7nNS-fwMZV4t_XCfDA-tAx5w7SrWWsM+YBGA@mail.gmail.com","threadId":"32451","inReplyTo":"20121224073103.GA10793@zuhnb712","subject":"Re: Find the starting point of a local branch","fromName":"Kevin","fromEmail":"ikke@ikke.info","sentAt":"2012-12-24T09:12:51Z","receivedAt":"2012-12-24T09:12:51Z","isPatch":false,"sender":{"key":"ikke@ikke.info","avatar":"https://gravatar.com/avatar/60a0d08eeccb16914fdbfc7f3441548dc827dc436d5c6900ec6600e274e53c5b?d=mp&s=160"},"body":"On Mon, Dec 24, 2012 at 8:31 AM, Woody Wu <narkewoody@gmail.com> wrote:\n> But thanks anyway, I see you guys's discussions and it's a little hard\n> to understand to me at the moment. Currently, I still have to use gitk\n> with narrowed outputs.\n\nEach commit refers to it's parent. If you take a branch, and keep\nfollowing the first parent of the commits, you will finally reach the\nroot commit (the first commit made). You don't see any branches, it's\njust one straight line. That's why git can't tell you where a branch\nstarted, because it all looks like a single branch to git.\n\nWith merge-base, you basically give git two branches, and git finds\nthe first ancestor that is common to both branches.\n\nSee [1] for an example. If you follow the arrows from branch a, you\nget from E to A (note that commit C doesn't know about commit F\npointing to it). So it looks like there is only a single branch.\n\nIf you do git merge-base a b, git sees both branches have commit C in\ncommon, and reports that as the merge-base.\n\n[1]: http://g.jk.gs/9W.png\n"},{"id":"205467","messageId":"CACsJy8Dt94XLSa8Sg3T0URJYG9cHD_sUySuhm3Vu4ESy-VrXag@mail.gmail.com","threadId":"32451","inReplyTo":"20121224061938.GA25186@sigill.intra.peff.net","subject":"Re: Find the starting point of a local branch","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2012-12-24T11:16:05Z","receivedAt":"2012-12-24T11:16:05Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Dec 24, 2012 at 1:19 PM, Jeff King <peff@peff.net> wrote:\n> On Mon, Dec 24, 2012 at 12:28:45PM +0700, Nguyen Thai Ngoc Duy wrote:\n>\n>> > You want to know \"what commit was I at when I typed `git branch\n>> > mybranch`\"?  The problem is git doesn't record this information and\n>> > doesn't have the slightest clue.\n>>\n>> Maybe we should store this information. reflog is a perfect place for\n>> this, I think. If this information is reliably available, git rebase\n>> can be told to \"rebase my whole branch\" instead of my choosing the\n>> base commit for it.\n>\n> Is that what you really want, though? We record the \"upstream\" branch\n> already, and you can calculate the merge base with that branch to see\n> which commits are unique to your branch. In simple cases, that is the\n> same as \"where did I start the branch\". In more complex cases, it may\n> not be (e.g., if you merged some of the early commits in the branch\n> already).  But in that latter case, would you really want to rebase\n> those commits that had been merged?\n>\n> The reason that git does not bother storing \"where did I start this\n> branch\" is that it is usually not useful. The right question is usually\n> \"what is the merge base\". There are exceptions, of course (e.g., if you\n> are asking something like \"what work did I do while checked out on the\n> 'foo' branch\"). But for merging and rebasing, I think the computed\n> merge-base is much more likely to do what people want.\n\nRebasing is exactly why I want this. Merge base works most of the time\nuntil you rewrite upstream (which I do sometimes). There are also\ncases when I create a branch without upstream, or when upstream is\nrenamed. Still, making \"rebase -i --topic\" == \"rebase -i $(git\nmerge-base HEAD @{upstream})\" would be cool.\n-- \nDuy\n"},{"id":"205468","messageId":"CACsJy8DMGrHqgY7himfJA-6f5beZ83Pje+-ex62LQOAARWh=Nw@mail.gmail.com","threadId":"32451","inReplyTo":"7vmwx4newy.fsf@alter.siamese.dyndns.org","subject":"Re: Find the starting point of a local branch","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2012-12-24T11:21:15Z","receivedAt":"2012-12-24T11:21:15Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Dec 24, 2012 at 1:27 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:\n>\n>> On Mon, Dec 24, 2012 at 12:34 PM, Tomas Carnecky\n>> <tomas.carnecky@gmail.com> wrote:\n>>>> Maybe we should store this information. reflog is a perfect place for\n>>>> this, I think. If this information is reliably available, git rebase\n>>>> can be told to \"rebase my whole branch\" instead of my choosing the\n>>>> base commit for it.\n>>>\n>>> What's the starting point of the branch if I type: git branch foo <commit-ish>?\n>>\n>> You start working off <commit-ish> so I think the starting point would\n>> be <commit-ish>.\n>\n> Yeah, that sounds sensible.  Don't we already have it in the reflog,\n> though?\n\nI looked briefly at reflog before writing my previous mail and noticed\nthat when I create a new branch (usually using \"git checkout -b branch\nref\") it does not record the base commit.\n\n> What is trickier is when you later transplant it to some other base\n> (perhaps prepare a topic on 'master', realize it should better apply\n> to 'maint' and move it there).  If the user did the transplanting by\n> hand, reflog would probably not have enough information, e.g. after\n>\n>     $ git checkout maint^0\n>     $ git log --oneline master..topic\n>     $ git cherry-pick $one_of_the_commit_names_you_see_in_the_above\n>     $ git cherry-pick $another_commit_name_you_see_in_the_above\n>       ...\n>     $ git branch -f topic\n>\n> no reflog other than HEAD@{} will tell you that you were at maint^0,\n> so the reflog of topic wouldn't know it \"forked\" from there, either.\n\nWe could at least invalidate the recorded base in reflog and let user\ndefine a new one (I hope).\n-- \nDuy\n"},{"id":"205474","messageId":"20121224153415.GA28670@sigill.intra.peff.net","threadId":"32451","inReplyTo":"CACsJy8Dt94XLSa8Sg3T0URJYG9cHD_sUySuhm3Vu4ESy-VrXag@mail.gmail.com","subject":"Re: Find the starting point of a local branch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2012-12-24T15:34:15Z","receivedAt":"2012-12-24T15:34:15Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Dec 24, 2012 at 06:16:05PM +0700, Nguyen Thai Ngoc Duy wrote:\n\n> > The reason that git does not bother storing \"where did I start this\n> > branch\" is that it is usually not useful. The right question is usually\n> > \"what is the merge base\". There are exceptions, of course (e.g., if you\n> > are asking something like \"what work did I do while checked out on the\n> > 'foo' branch\"). But for merging and rebasing, I think the computed\n> > merge-base is much more likely to do what people want.\n> \n> Rebasing is exactly why I want this. Merge base works most of the time\n> until you rewrite upstream (which I do sometimes).\n\nTrue, although wouldn't you generally want to rebase it on top of the\nrewritten upstream in that case (which is what \"pull --rebase\" will do,\nby scanning the reflog for the last version of the upstream that you\nactually built on).\n\n> There are also cases when I create a branch without upstream, or when\n> upstream is renamed. Still, making \"rebase -i --topic\" == \"rebase -i\n> $(git merge-base HEAD @{upstream})\" would be cool.\n\nYeah. I usually just do \"rebase -i @{upstream}\" which picks the same\ncommits, but moves to the updated version of upstream (IOW, I both\nrewrite and move forward at the same time). But there is value in\nrewriting without moving forward in many workflows. That seems like a\nsensible feature to me.\n\n-Peff\n"},{"id":"205475","messageId":"CANiSa6iSYvLbp1s8h9pwi=P1m0QdZPqf06hAm+4muChgJUuj=g@mail.gmail.com","threadId":"32451","inReplyTo":"20121224073103.GA10793@zuhnb712","subject":"Re: Find the starting point of a local branch","fromName":"Martin von Zweigbergk","fromEmail":"martinvonz@gmail.com","sentAt":"2012-12-24T17:24:39Z","receivedAt":"2012-12-24T17:24:39Z","isPatch":false,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"On Sun, Dec 23, 2012 at 11:31 PM, Woody Wu <narkewoody@gmail.com> wrote:\n> On Sun, Dec 23, 2012 at 11:09:58PM -0500, Seth Robertson wrote:\n>>\n>> In message <20121224035825.GA17203@zuhnb712>, Woody Wu writes:\n>>\n>>     How can I find out what's the staring reference point (a commit number\n>>     or tag name) of a locally created branch? I can use gitk to find out it\n>>     but this method is slow, I think there might be a command line to do it\n>>     quickly.\n>>\n>> The answer is more complex than you probably suspected.\n>>\n>> Technically, `git log --oneline mybranch | tail -n 1` will tell you\n>> the starting point of any branch.  But...I'm sure that isn't what you\n>> want to know.\n>>\n>> You want to know \"what commit was I at when I typed `git branch\n>> mybranch`\"?\n>\n> Yes, this is exactly I want to know.\n>\n>>The problem is git doesn't record this information and\n>> doesn't have the slightest clue.\n>>\n>> But, you say, I can use `gitk` and see it.  See?  Right there.  That\n>> isn't (necessarily) the \"starting point\" of the branch, it is the\n>> place where your branch diverged from some other branch.  Git is\n>> actually quite able to tell you when the last time your branch\n>> diverged from some other branch.  `git merge-base mybranch master`\n>> will tell you this, and is probably the answer you were looking for.\n>\n> This is not working to me since I have more than one local branch that\n> diverged from the master, and in fact, the branch I have in question was\n> diverged from another local branch.\n\nAs Jeff mentions in a later message, \"git pull --rebase\" would\nprobably do what you want. It works with local branches too.\n\nI once tried to add the same cleverness that \"git pull --rebase\"\ndirectly in \"git rebase\" [1], but there were several issues with those\npatches, one of was regarding the performance (\"git pull --rebase\" can\nbe equally slow, but since it often involves network, users probably\nrarely notice). I think it would be nice to at least add it as an\noption to \"git rebase\" some day. Until then, \"git pull --rebase\" works\nfine.\n\n [1] http://thread.gmane.org/gmane.comp.version-control.git/166710\n"},{"id":"205476","messageId":"7vbodjnu5c.fsf@alter.siamese.dyndns.org","threadId":"32451","inReplyTo":"CACsJy8DMGrHqgY7himfJA-6f5beZ83Pje+-ex62LQOAARWh=Nw@mail.gmail.com","subject":"Re: Find the starting point of a local branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-24T19:10:23Z","receivedAt":"2012-12-24T19:10:23Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:\n\n> On Mon, Dec 24, 2012 at 1:27 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:\n>>\n>>> On Mon, Dec 24, 2012 at 12:34 PM, Tomas Carnecky\n>>> <tomas.carnecky@gmail.com> wrote:\n>>>>> Maybe we should store this information. reflog is a perfect place for\n>>>>> this, I think. If this information is reliably available, git rebase\n>>>>> can be told to \"rebase my whole branch\" instead of my choosing the\n>>>>> base commit for it.\n>>>>\n>>>> What's the starting point of the branch if I type: git branch foo <commit-ish>?\n>>>\n>>> You start working off <commit-ish> so I think the starting point would\n>>> be <commit-ish>.\n>>\n>> Yeah, that sounds sensible.  Don't we already have it in the reflog,\n>> though?\n>\n> I looked briefly at reflog before writing my previous mail and noticed\n> that when I create a new branch (usually using \"git checkout -b branch\n> ref\") it does not record the base commit.\n\nHmph.  Perhaps you are referring to something different than what I\nthink \"the base commit\" with that word.\n\n    $ git reflog mz/pick-unborn | tail -n 1\n    b3cf6f3 mz/pick-unborn@{3}: branch: Created from ko/master\n\n>> What is trickier is when you later transplant it to some other base\n>> (perhaps prepare a topic on 'master', realize it should better apply\n>> to 'maint' and move it there).  If the user did the transplanting by\n>> hand, reflog would probably not have enough information, e.g. after\n>>\n>>     $ git checkout maint^0\n>>     $ git log --oneline master..topic\n>>     $ git cherry-pick $one_of_the_commit_names_you_see_in_the_above\n>>     $ git cherry-pick $another_commit_name_you_see_in_the_above\n>>       ...\n>>     $ git branch -f topic\n>>\n>> no reflog other than HEAD@{} will tell you that you were at maint^0,\n>> so the reflog of topic wouldn't know it \"forked\" from there, either.\n>\n> We could at least invalidate the recorded base in reflog and let user\n> define a new one (I hope).\n\nPlease do not even think about going back and rewrite to lose\ninformation.  If the records have full information, you should be\nable to reconstruct what you want from it without rewriting.\n\nEven more importantly, wish to \"invalidate\" indicates that you know\nat a newer point that you have more authoritative information than\nthe older reflog entries, so you should be able to do the moral\nequivalent by writing the event as establishing a new base at that\npoint (e.g. \"checkout -B\"), and stopping at that point in the reflog\nwhen reading, without losing the older reflog entries.\n"},{"id":"205480","messageId":"CACsJy8ChvEMt7FMs-zdyF9SOhL8U01x266OebEk3SHR+19908g@mail.gmail.com","threadId":"32451","inReplyTo":"7vbodjnu5c.fsf@alter.siamese.dyndns.org","subject":"Re: Find the starting point of a local branch","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2012-12-25T01:09:17Z","receivedAt":"2012-12-25T01:09:17Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Dec 25, 2012 at 2:10 AM, Junio C Hamano <gitster@pobox.com> wrote:\n>> I looked briefly at reflog before writing my previous mail and noticed\n>> that when I create a new branch (usually using \"git checkout -b branch\n>> ref\") it does not record the base commit.\n>\n> Hmph.  Perhaps you are referring to something different than what I\n> think \"the base commit\" with that word.\n>\n>     $ git reflog mz/pick-unborn | tail -n 1\n>     b3cf6f3 mz/pick-unborn@{3}: branch: Created from ko/master\n\nNo you're right. My reflogs must be pruned. Creating a new branch does\nproduce that entry.\n\n>> We could at least invalidate the recorded base in reflog and let user\n>> define a new one (I hope).\n>\n> Please do not even think about going back and rewrite to lose\n> information.  If the records have full information, you should be\n> able to reconstruct what you want from it without rewriting.\n>\n> Even more importantly, wish to \"invalidate\" indicates that you know\n> at a newer point that you have more authoritative information than\n> the older reflog entries, so you should be able to do the moral\n> equivalent by writing the event as establishing a new base at that\n> point (e.g. \"checkout -B\"), and stopping at that point in the reflog\n> when reading, without losing the older reflog entries.\n\nExactly. And when we prune the reflog, we could add the base back so\nthe base is always in reflog.\n-- \nDuy\n"},{"id":"205581","messageId":"20121228051514.GA4028@zuhnb712.ap.bm.net","threadId":"32451","inReplyTo":"CANiSa6iSYvLbp1s8h9pwi=P1m0QdZPqf06hAm+4muChgJUuj=g@mail.gmail.com","subject":"Re: Find the starting point of a local branch","fromName":"Woody Wu","fromEmail":"narkewoody@gmail.com","sentAt":"2012-12-28T05:15:15Z","receivedAt":"2012-12-28T05:15:15Z","isPatch":false,"sender":{"key":"narkewoody@gmail.com","avatar":null},"body":"On Mon, Dec 24, 2012 at 09:24:39AM -0800, Martin von Zweigbergk wrote:\n> On Sun, Dec 23, 2012 at 11:31 PM, Woody Wu <narkewoody@gmail.com> wrote:\n> > On Sun, Dec 23, 2012 at 11:09:58PM -0500, Seth Robertson wrote:\n> >>\n> >> In message <20121224035825.GA17203@zuhnb712>, Woody Wu writes:\n> >>\n> >>     How can I find out what's the staring reference point (a commit number\n> >>     or tag name) of a locally created branch? I can use gitk to find out it\n> >>     but this method is slow, I think there might be a command line to do it\n> >>     quickly.\n> >>\n> >> The answer is more complex than you probably suspected.\n> >>\n> >> Technically, `git log --oneline mybranch | tail -n 1` will tell you\n> >> the starting point of any branch.  But...I'm sure that isn't what you\n> >> want to know.\n> >>\n> >> You want to know \"what commit was I at when I typed `git branch\n> >> mybranch`\"?\n> >\n> > Yes, this is exactly I want to know.\n> >\n> >>The problem is git doesn't record this information and\n> >> doesn't have the slightest clue.\n> >>\n> >> But, you say, I can use `gitk` and see it.  See?  Right there.  That\n> >> isn't (necessarily) the \"starting point\" of the branch, it is the\n> >> place where your branch diverged from some other branch.  Git is\n> >> actually quite able to tell you when the last time your branch\n> >> diverged from some other branch.  `git merge-base mybranch master`\n> >> will tell you this, and is probably the answer you were looking for.\n> >\n> > This is not working to me since I have more than one local branch that\n> > diverged from the master, and in fact, the branch I have in question was\n> > diverged from another local branch.\n> \n> As Jeff mentions in a later message, \"git pull --rebase\" would\n> probably do what you want. It works with local branches too.\n> \n\nI think what 'git pull --rebase' would do is to fetch from the origin\nand do a 'git rebase'.  On one hand, I don't understand 'git rebase' so\nmuch from the manual, ont the other hand, I did not get the point why\n'git rebase' has something to do with the thing I want to do (what I\nwant is just query some kind of history information).\n\nI know, my knowledge about git is still so limit. I will keep study from\nthe man pages.\n\n\n> I once tried to add the same cleverness that \"git pull --rebase\"\n> directly in \"git rebase\" [1], but there were several issues with those\n> patches, one of was regarding the performance (\"git pull --rebase\" can\n> be equally slow, but since it often involves network, users probably\n> rarely notice). I think it would be nice to at least add it as an\n> option to \"git rebase\" some day. Until then, \"git pull --rebase\" works\n> fine.\n> \n>  [1] http://thread.gmane.org/gmane.comp.version-control.git/166710\n\n-- \nwoody\nI can't go back to yesterday - because I was a different person then.\n"},{"id":"205584","messageId":"CANiSa6iuiuDxjTdn9-DD3y2-OA=jffxGM0ibVrZB1ixLy0i+Gg@mail.gmail.com","threadId":"32451","inReplyTo":"20121228051514.GA4028@zuhnb712.ap.bm.net","subject":"Re: Find the starting point of a local branch","fromName":"Martin von Zweigbergk","fromEmail":"martinvonz@gmail.com","sentAt":"2012-12-28T06:38:25Z","receivedAt":"2012-12-28T06:38:25Z","isPatch":false,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"On Thu, Dec 27, 2012 at 9:15 PM, Woody Wu <narkewoody@gmail.com> wrote:\n> On Mon, Dec 24, 2012 at 09:24:39AM -0800, Martin von Zweigbergk wrote:\n>> On Sun, Dec 23, 2012 at 11:31 PM, Woody Wu <narkewoody@gmail.com> wrote:\n>> >\n>> > This is not working to me since I have more than one local branch that\n>> > diverged from the master, and in fact, the branch I have in question was\n>> > diverged from another local branch.\n>>\n>> As Jeff mentions in a later message, \"git pull --rebase\" would\n>> probably do what you want. It works with local branches too.\n>>\n>\n> I think what 'git pull --rebase' would do is to fetch from the origin\n> and do a 'git rebase'.\n\nNot if the configured upstream is a local branch (see the\n\"branch.<name>.*\" configuration variables). In that case it will just\nrebase the local branch onto the new position of its upstream. If the\nupstream is not configured, I believe you can still do \"git pull\n--rebase . <upstream branch>\".\n\n> On one hand, I don't understand 'git rebase' so\n> much from the manual, ont the other hand, I did not get the point why\n> 'git rebase' has something to do with the thing I want to do (what I\n> want is just query some kind of history information).\n\nI may have misunderstood or assumed things incorrectly that you wanted\nto rebase the commits on your branch. So why do you want to know?\n(Please ignore me if this was answered elsewhere in the thread that I\nmight have missed.)\n\nAnyway, to answer your question, you could use a method similar to\nwhat \"git pull --rebase\" uses internally to figure out the branch\npoint:\n\ngit merge-base $(git rev-parse <branch>) $(git rev-list -g <upstream branch>)\n\nHope that helps\n"}]}