threads / patch / 39827

patchDocumentation clarification on git-checkout regarding ours/theirs

Subject: [PATCH] Documentation clarification on git-checkout regarding ours/theirs

## tl;dr

4 messages between Jul 10, 2015 and Jul 12, 2015. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Simon A. Eugster· Jul 10, 2015, 08:27 UTC · lore
From: "Simon A. Eugster" <simon.eugster@eps.ch>
Signed-off-by: Simon A. Eugster <simon.eugster@eps.ch>
---
 Documentation/git-checkout.txt | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
Show changes to Documentation/git-checkout.txt +15 −1
diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
index d263a56..d69306f 100644
--- a/Documentation/git-checkout.txt
+++ b/Documentation/git-checkout.txt
@@ -115,7 +115,21 @@ entries; instead, unmerged entries are ignored.
 --ours::
 --theirs::
 	When checking out paths from the index, check out stage #2
-	('ours') or #3 ('theirs') for unmerged paths.
+	('ours', HEAD) or #3 ('theirs', MERGE_HEAD) for unmerged paths.
+	See linkgit:git-merge[1] for details about stages #2 and #3.
++
+Note that during `git rebase` and `git pull --rebase`, 'theirs' checks out
+the local version, and 'ours' the remote version or the history that is rebased
+against.
++
+The reason ours/theirs appear to be swapped during a rebase is that we
+define the remote history as the canonical history, on top of which our
+private commits are applied on, as opposed to normal merging where the
+local history is the canonical one.
+During merging, we assume the role of the canonical history’s keeper,
+which, in case of a rebase, is the remote history, and our private commits
+look to the keeper as “their” commits which need to be integrated on top
+of “our” work.
 
 -b <new_branch>::
 	Create a new branch named <new_branch> and start it at
-- 
1.8.5.1
Junio C Hamano· Jul 10, 2015, 20:07 UTC · re: Simon A. Eugster · lore

Re: [PATCH] Documentation clarification on git-checkout regarding ours/theirs

"Simon A. Eugster" <simon.eu@gmail.com> writes:
> From: "Simon A. Eugster" <simon.eugster@eps.ch>
>
> Signed-off-by: Simon A. Eugster <simon.eugster@eps.ch>
> ---

For those who are looking from the sideline, this is a reroll from a month-old thread $gmane/271680.

Show 13 quoted lines
>  Documentation/git-checkout.txt | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
> index d263a56..d69306f 100644
> --- a/Documentation/git-checkout.txt
> +++ b/Documentation/git-checkout.txt
> @@ -115,7 +115,21 @@ entries; instead, unmerged entries are ignored.
>  --ours::
>  --theirs::
>  	When checking out paths from the index, check out stage #2
> -	('ours') or #3 ('theirs') for unmerged paths.
> +	('ours', HEAD) or #3 ('theirs', MERGE_HEAD) for unmerged paths.

I'd drop the change on this line. Your conflict may or may not be from these two places when you are using "checkout". Even if it came from "git merge", when you are doing "merge", the roles 'ours' and 'theirs' are very clear and mentioning HEAD/MERGE_HEAD does not add more clarity than it clutters the description, I would think.

Show 10 quoted lines
> +	See linkgit:git-merge[1] for details about stages #2 and #3.
> ++
> +Note that during `git rebase` and `git pull --rebase`, 'theirs' checks out
> +the local version, and 'ours' the remote version or the history that is rebased
> +against.
> ++
> +The reason ours/theirs appear to be swapped during a rebase is that we
> +define the remote history as the canonical history, on top of which our
> +private commits are applied on, as opposed to normal merging where the
> +local history is the canonical one.

It appears to me that this patch text predates my comment in $gmane/271720 and your response to it?

Show 7 quoted lines
> +During merging, we assume the role of the canonical history’s keeper,
> +which, in case of a rebase, is the remote history, and our private commits
> +look to the keeper as “their” commits which need to be integrated on top
> +of “our” work.
>  
>  -b <new_branch>::
>  	Create a new branch named <new_branch> and start it at

Thanks for reminding of the discussion that did not conclude with a patch.

How about this?
-- >8 --
From: "Simon A. Eugster" <simon.eugster@eps.ch>
Subject: checkout: document subtlety around --ours/--theirs

During a 'rebase' (hence 'pull --rebase'), --ours/--theirs may appear to be swapped to those who are not aware of the fact that they are temporarily playing the role of the keeper of the more authoritative history.

Add a note to clarify.
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Simon A. Eugster <simon.eugster@eps.ch>
---
 Documentation/git-checkout.txt | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
Show changes to Documentation/git-checkout.txt +15 −0
diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
index d263a565..8c921e7 100644
--- a/Documentation/git-checkout.txt
+++ b/Documentation/git-checkout.txt
@@ -116,6 +116,21 @@ entries; instead, unmerged entries are ignored.
 --theirs::
 	When checking out paths from the index, check out stage #2
 	('ours') or #3 ('theirs') for unmerged paths.
++
+Note that during `git rebase` and `git pull --rebase`, 'ours' and
+'theirs' may appear swapped; `--ours` gives the version from the
+branch the changes are rebased onto, while `--theirs` gives the
+version from the branch that holds your work that is being rebased.
++
+This is because `rebase` is used in a workflow that treats the
+history at the remote as the shared canonical one, and treat the
+work done on the branch you are rebasing as the third-party work to
+be integrated, and you are temporarily assuming the role of the
+keeper of the canonical history during the rebase.  As the keeper of
+the canonical history, you need to view the history from the remote
+as `ours` (i.e. "our shared canonical history"), while what you did
+on your side branch as `theirs` (i.e. "one contributor's work on top
+of it").
 
 -b <new_branch>::
 	Create a new branch named <new_branch> and start it at
Simon A. Eugster· Jul 11, 2015, 05:26 UTC · re: Junio C Hamano · lore

Re: [PATCH] Documentation clarification on git-checkout regarding ours/theirs

Am 10.07.2015 um 22:07 schrieb Junio C Hamano:
Show 29 quoted lines
> "Simon A. Eugster" <simon.eu@gmail.com> writes:
>
>> From: "Simon A. Eugster" <simon.eugster@eps.ch>
>>
>> Signed-off-by: Simon A. Eugster <simon.eugster@eps.ch>
>> ---
>
> For those who are looking from the sideline, this is a reroll from a
> month-old thread $gmane/271680.
>
>>   Documentation/git-checkout.txt | 16 +++++++++++++++-
>>   1 file changed, 15 insertions(+), 1 deletion(-)
>>
>> diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
>> index d263a56..d69306f 100644
>> --- a/Documentation/git-checkout.txt
>> +++ b/Documentation/git-checkout.txt
>> @@ -115,7 +115,21 @@ entries; instead, unmerged entries are ignored.
>>   --ours::
>>   --theirs::
>>   	When checking out paths from the index, check out stage #2
>> -	('ours') or #3 ('theirs') for unmerged paths.
>> +	('ours', HEAD) or #3 ('theirs', MERGE_HEAD) for unmerged paths.
>
> I'd drop the change on this line.  Your conflict may or may not be
> from these two places when you are using "checkout".  Even if it
> came from "git merge", when you are doing "merge", the roles 'ours'
> and 'theirs' are very clear and mentioning HEAD/MERGE_HEAD does not
> add more clarity than it clutters the description, I would think.

Agree! How about the reference to git-merge? I had to google for stage to find the documentation on it.

Show 14 quoted lines
>
>> +	See linkgit:git-merge[1] for details about stages #2 and #3.
>> ++
>> +Note that during `git rebase` and `git pull --rebase`, 'theirs' checks out
>> +the local version, and 'ours' the remote version or the history that is rebased
>> +against.
>> ++
>> +The reason ours/theirs appear to be swapped during a rebase is that we
>> +define the remote history as the canonical history, on top of which our
>> +private commits are applied on, as opposed to normal merging where the
>> +local history is the canonical one.
>
> It appears to me that this patch text predates my comment in
> $gmane/271720 and your response to it?
Yes.
Show 56 quoted lines
>> +During merging, we assume the role of the canonical history’s keeper,
>> +which, in case of a rebase, is the remote history, and our private commits
>> +look to the keeper as “their” commits which need to be integrated on top
>> +of “our” work.
>>
>>   -b <new_branch>::
>>   	Create a new branch named <new_branch> and start it at
>
> Thanks for reminding of the discussion that did not conclude with a
> patch.
>
> How about this?
>
> -- >8 --
> From: "Simon A. Eugster" <simon.eugster@eps.ch>
> Subject: checkout: document subtlety around --ours/--theirs
>
> During a 'rebase' (hence 'pull --rebase'), --ours/--theirs may
> appear to be swapped to those who are not aware of the fact that
> they are temporarily playing the role of the keeper of the more
> authoritative history.
>
> Add a note to clarify.
>
> Helped-by: Junio C Hamano <gitster@pobox.com>
> Signed-off-by: Simon A. Eugster <simon.eugster@eps.ch>
> ---
>   Documentation/git-checkout.txt | 15 +++++++++++++++
>   1 file changed, 15 insertions(+)
>
> diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
> index d263a565..8c921e7 100644
> --- a/Documentation/git-checkout.txt
> +++ b/Documentation/git-checkout.txt
> @@ -116,6 +116,21 @@ entries; instead, unmerged entries are ignored.
>   --theirs::
>   	When checking out paths from the index, check out stage #2
>   	('ours') or #3 ('theirs') for unmerged paths.
> ++
> +Note that during `git rebase` and `git pull --rebase`, 'ours' and
> +'theirs' may appear swapped; `--ours` gives the version from the
> +branch the changes are rebased onto, while `--theirs` gives the
> +version from the branch that holds your work that is being rebased.
> ++
> +This is because `rebase` is used in a workflow that treats the
> +history at the remote as the shared canonical one, and treat the
> +work done on the branch you are rebasing as the third-party work to
> +be integrated, and you are temporarily assuming the role of the
> +keeper of the canonical history during the rebase.  As the keeper of
> +the canonical history, you need to view the history from the remote
> +as `ours` (i.e. "our shared canonical history"), while what you did
> +on your side branch as `theirs` (i.e. "one contributor's work on top
> +of it").
>
>   -b <new_branch>::
>   	Create a new branch named <new_branch> and start it at

I think there is an “s” missing in “… and treat the work done on the branch …”, but not quite sure.

Apart from this, very clear and perfect to me.

Thanks for your effort! Simon

Junio C Hamano· Jul 12, 2015, 16:36 UTC · re: Simon A. Eugster · lore

Re: [PATCH] Documentation clarification on git-checkout regarding ours/theirs

"Simon A. Eugster" <simon.eu@gmail.com> writes:
Show 11 quoted lines
>> +...  As the keeper of
>> +the canonical history, you need to view the history from the remote
>> +as `ours` (i.e. "our shared canonical history"), while what you did
>> +on your side branch as `theirs` (i.e. "one contributor's work on top
>> +of it").
>>
>>   -b <new_branch>::
>>   	Create a new branch named <new_branch> and start it at
>
> I think there is an “s” missing in “… and treat the work done on
> the branch …”, but not quite sure.
Thanks, you are right.  Will fix.

← back to recent threads