{"thread":{"id":"13390","subject":"[PATCH] Make rebase save ORIG_HEAD if using current branch","startedAt":"2008-05-06T05:19:20Z","lastAt":"2008-05-07T14:30:21Z","messageCount":5,"participants":["Brian Gernhardt","Johannes Sixt","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"76173","messageId":"20080506051920.GA9165@Hermes.local","threadId":"13390","inReplyTo":null,"subject":"[PATCH] Make rebase save ORIG_HEAD if using current branch","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2008-05-06T05:19:20Z","receivedAt":"2008-05-06T05:19:20Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"This makes rebase act a little more like merge when working on the\ncurrent branch.  This is particularly useful for `git pull --rebase`\n\nSigned-off-by: Brian Gernhardt <benji@silverinsanity.com>\n---\n\n I was trying to figure out why reviewing the new changes in git was so\n hard using my `git log ORIG_HEAD..` alias.  Turns out my ORIG_HEAD\n hadn't been updated since Feburary, which is when I set\n branch.master.rebase to true.\n\n I think ORIG_HEAD should be set every time a pull changes HEAD, whether\n by a merge or rebase.  Making rebase act like merge seemed more elegant\n than having git-pull set ORIG_HEAD iff using rebase.\n\n git-rebase.sh |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 9b13b83..8d54d9f 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -342,6 +342,7 @@ case \"$#\" in\n \t\tbranch_name=HEAD ;# detached\n \tfi\n \tbranch=$(git rev-parse --verify \"${branch_name}^0\") || exit\n+\techo \"$branch\" > \"$GIT_DIR/ORIG_HEAD\"\n \t;;\n esac\n orig_head=$branch\n-- \n1.5.5.1.242.g558e8\n"},{"id":"76177","messageId":"481FFB62.9090804@viscovery.net","threadId":"13390","inReplyTo":"20080506051920.GA9165@Hermes.local","subject":"Re: [PATCH] Make rebase save ORIG_HEAD if using current branch","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2008-05-06T06:32:02Z","receivedAt":"2008-05-06T06:32:02Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Brian Gernhardt schrieb:\n> diff --git a/git-rebase.sh b/git-rebase.sh\n> index 9b13b83..8d54d9f 100755\n> --- a/git-rebase.sh\n> +++ b/git-rebase.sh\n> @@ -342,6 +342,7 @@ case \"$#\" in\n>  \t\tbranch_name=HEAD ;# detached\n>  \tfi\n>  \tbranch=$(git rev-parse --verify \"${branch_name}^0\") || exit\n> +\techo \"$branch\" > \"$GIT_DIR/ORIG_HEAD\"\n\n1. You should be using 'git update-ref' here, I think.\n2. You should detect errors.\n3. Should ORIG_HEAD better be set at the end of the rebase, not at the\nbeginning? Because if the rebase stops for some reason, and then you do a\n'git reset', you'll have overwritten the ORIG_HEAD that you have set here.\n\n-- Hannes\n"},{"id":"76215","messageId":"54536F65-3A06-482E-9806-2E4F643C1024@silverinsanity.com","threadId":"13390","inReplyTo":"481FFB62.9090804@viscovery.net","subject":"Re: [PATCH] Make rebase save ORIG_HEAD if using current branch","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2008-05-06T17:45:04Z","receivedAt":"2008-05-06T17:45:04Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"\nOn May 6, 2008, at 2:32 AM, Johannes Sixt wrote:\n\n> Brian Gernhardt schrieb:\n>> diff --git a/git-rebase.sh b/git-rebase.sh\n>> index 9b13b83..8d54d9f 100755\n>> --- a/git-rebase.sh\n>> +++ b/git-rebase.sh\n>> @@ -342,6 +342,7 @@ case \"$#\" in\n>> \t\tbranch_name=HEAD ;# detached\n>> \tfi\n>> \tbranch=$(git rev-parse --verify \"${branch_name}^0\") || exit\n>> +\techo \"$branch\" > \"$GIT_DIR/ORIG_HEAD\"\n>\n> 1. You should be using 'git update-ref' here, I think.\n> 2. You should detect errors.\n\nThis is exactly how git-merge.sh does it.  While that's not a good  \nargument for adding this, perhaps merge should be updated as well.   \nAnd presumably update-ref will make detecting errors easy.  But is  \nbeing unable to set ORIG_HEAD an error that should stop the entire  \nprocess?\n\n> 3. Should ORIG_HEAD better be set at the end of the rebase, not at the\n> beginning? Because if the rebase stops for some reason, and then you  \n> do a\n> 'git reset', you'll have overwritten the ORIG_HEAD that you have set  \n> here.\n\nI put it where I did because I thought it would only make sense when  \nrebasing the current HEAD (instead of the two argument version that  \nswitches first).  Duplicating the logic to determine that later seemed  \nwasteful.  Also, might you want to access the original HEAD during a  \nrebase conflict?  (Although that would argue that ORIG_HEAD should be  \nset for all rebases, to $upstream.)\n\n~~ Brian\n"},{"id":"76256","messageId":"482164F6.4010205@viscovery.net","threadId":"13390","inReplyTo":"54536F65-3A06-482E-9806-2E4F643C1024@silverinsanity.com","subject":"Re: [PATCH] Make rebase save ORIG_HEAD if using current branch","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2008-05-07T08:14:46Z","receivedAt":"2008-05-07T08:14:46Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Brian Gernhardt schrieb:\n> On May 6, 2008, at 2:32 AM, Johannes Sixt wrote:\n>> Brian Gernhardt schrieb:\n>>> +    echo \"$branch\" > \"$GIT_DIR/ORIG_HEAD\"\n>>\n>> 1. You should be using 'git update-ref' here, I think.\n>> 2. You should detect errors.\n> \n> This is exactly how git-merge.sh does it.  While that's not a good\n> argument for adding this, perhaps merge should be updated as well.  And\n> presumably update-ref will make detecting errors easy.  But is being\n> unable to set ORIG_HEAD an error that should stop the entire process?\n\nProbably not.\n\n>> 3. Should ORIG_HEAD better be set at the end of the rebase, not at the\n>> beginning? Because if the rebase stops for some reason, and then you do a\n>> 'git reset', you'll have overwritten the ORIG_HEAD that you have set\n>> here.\n> \n> I put it where I did because I thought it would only make sense when\n> rebasing the current HEAD (instead of the two argument version that\n> switches first).  Duplicating the logic to determine that later seemed\n> wasteful.  Also, might you want to access the original HEAD during a\n> rebase conflict?  (Although that would argue that ORIG_HEAD should be\n> set for all rebases, to $upstream.)\n\nWell, I can't think of a use-case where ORIG_HEAD would be extremly useful\nfor _me_, but you argued for one (git pull --rebase), so you make it so\nthat it suits you. I'm just drawing a scenario where ORIG_HEAD possibly is\nnot what you expect.\n\n-- Hannes\n"},{"id":"76283","messageId":"7vbq3ifapu.fsf@gitster.siamese.dyndns.org","threadId":"13390","inReplyTo":"482164F6.4010205@viscovery.net","subject":"Re: [PATCH] Make rebase save ORIG_HEAD if using current branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-05-07T14:30:21Z","receivedAt":"2008-05-07T14:30:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j.sixt@viscovery.net> writes:\n\n>>> 3. Should ORIG_HEAD better be set at the end of the rebase, not at the\n>>> beginning? Because if the rebase stops for some reason, and then you do a\n>>> 'git reset', you'll have overwritten the ORIG_HEAD that you have set\n>>> here.\n\nVery true.  If the purpose of this is to view \"diff/log ORIG_HEAD..\" after\n\"pull --rebase\", setting it there does not make much sense.  In any case,\n\"diff/log branch@{1}...\" will give you the same information unless you are\nrebasing an already detached HEAD, so letting ORIG_HEAD get overwritten\nlike this patch does is not the end of the world, but then the original\nissue of the lack of ORIG_HEAD is not much of an issue either with that\nlogic.\n\nWhat the patch implements would be an ORIG_HEAD that only sometimes works\n(iow, does not work if you did reset during rebasing session), which is\nnot what people can rely on.  Teaching people a more reliable way of using\nreflog, which incidentally is also a consistent way between \"pull\" and\n\"pull --rebase\", might be better than that.  I would agree that the ideal\nthing is an ORIG_HEAD that always works, because it gives us the\nconsistency between the normal \"pull\" and \"pull --rebase\", though.\n\n>> ...  Also, might you want to access the original HEAD during a\n>> rebase conflict?  (Although that would argue that ORIG_HEAD should be\n>> set for all rebases, to $upstream.)\n\nI often find it useful to say \"show-branch HEAD topic\" while rebasing the\ntopic (gitk HEAD...topic would work equally well), taking advantage of the\nfact that the topic stays at the original position until rebase completes.\nYou do not need ORIG_HEAD pointing at anywhere to help that history\ninspection.\n\nI do not think setting ORIG_HEAD to $upstream (actually, it should be\n\"onto\") makes much sense.  After a normal \"pull\", what you can inspect\nwith \"diff/log ORIG_HEAD\" is the newly acquired history.  If we were to\nallow ORIG_HEAD to be used after a \"pull --rebase\" in a similar way, if\nyou make it point at \"the onto\" commit, \"diff/log ORIG_HEAD\" would show\nthe changes _you_ had before you did rebase that you carried forward, not\nthe new history you acquired with the \"pull --rebase\" operation.\n"}]}