git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] Documentation on git-checkout --ours/--theirs improved

From
Simon A. Eugster <simon.eu@gmail.com>
Date
Jun 15, 2015, 12:47 UTC
Message-ID
<1434372447-51230-3-git-send-email-simon.eu@gmail.com>
In-Reply-To
<1434372447-51230-1-git-send-email-simon.eu@gmail.com>
---
 Documentation/git-checkout.txt | 39 +++++++++++++++++++++++++++++++++++----
 1 file changed, 35 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
index 5c3ef86..ec0be28 100644
--- a/Documentation/git-checkout.txt
+++ b/Documentation/git-checkout.txt
@@ -116,10 +116,41 @@ entries; instead, unmerged entries are ignored.
 --theirs::
 	When checking out paths from the index, check out stage #2
 	('ours', HEAD) or #3 ('theirs', MERGE_HEAD) for unmerged paths.
-+
-After a `git pull --rebase`, for example, 'ours' points to the remote
-version and 'theirs' points to the local version. See linkgit:git-merge[1]
-for details about stages #2 and #3.
+	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.
++
+Normal merging:
+------------
+local ---------abC                  <-- canonical history
+                 | git checkout --ours
+                 v
+MERGE ---------abC
+                 ^
+                 | git checkout --theirs
+origin/master ---Xyz
+------------
+Rebasing:
+------------
+local -----------Abc
+                 | git checkout --theirs
+                 v
+REBASE --------xyZ
+                 ^
+                 | git checkout --ours
+origin/master -xyZ                    <-- canonical history
+------------
 
 -b <new_branch>::
 	Create a new branch named <new_branch> and start it at
-- 
1.8.5.1
Previous: Simon A. EugsterNext: Junio C Hamano
Message 5 of 10 in “Documentation clarification on git-checkout regarding ours/theirs”
  1. Documentation clarification on git-checkout regarding ours/theirsSimon A. Eugster, Jun 11, 2015
  2. Junio C HamanoJun 11, 2015
  3. Documentation clarification on git-checkoutSimon A. Eugster, Jun 15, 2015
  4. 1/2 Documentation clarification on git-checkout regarding ours/theirsSimon A. Eugster, Jun 15, 2015
  5. 2/2 Documentation on git-checkout --ours/--theirs improvedSimon A. Eugster, Jun 15, 2015
  6. Junio C HamanoJun 15, 2015
  7. Simon EugsterJun 16, 2015
  8. Junio C HamanoJun 16, 2015
  9. Simon EugsterJun 17, 2015
  10. Junio C HamanoJun 17, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.