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

[PATCH 4/6] Documentation: emphasize when git merge terminates early

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jan 11, 2010, 08:37 UTC
Message-ID
<20100111083754.GD23806@progeny.tock>
In-Reply-To
<20100111082123.GA23742@progeny.tock>
A merge-based operation in git can fail in two ways:
 - One that stops before touching anything (either your index was
   dirty and nothing happened, or your index was clean but you
   had local modifications in your work tree).
 - Another that goes ahead and results in conflicts.
The 'git merge' manual explains half of the first case as follows:
| A merge is always between the current `HEAD` and one or more
| commits (usually, branch head or tag), and the index file must
| match the tree of `HEAD` commit (i.e. the contents of the last commit)
| when it starts out.

The placement of this sentence makes it easy to skip over, and its formulation is perhaps too formal to be memorable.

So give this point its own section and expand upon it. Most of the added text is taken from <http://gitster.livejournal.com/25801.html>.

Cc: Petr Baudis <pasky@suse.cz>,
Cc: Junio C Hamano <gitster@pobox.com>
Cc: Thomas Rast <trast@student.ethz.ch>
Not-signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
This is not signed off because most of the text is from Junio’s
blog.  I hope that is okay.
 Documentation/git-merge.txt |   34 ++++++++++++++++++++++++----------
 1 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt
index e29bb97..8950aa4 100644
--- a/Documentation/git-merge.txt
+++ b/Documentation/git-merge.txt
@@ -60,6 +60,28 @@ include::merge-options.txt[]
 	least one <remote>.  Specifying more than one <remote>
 	obviously means you are trying an Octopus.
 
+PRE-MERGE CHECKS
+----------------
+
+In some other version control systems, you merge/update and then
+commit, with the risk of clobbering your changes with humongous
+conflicts. You shouldn't be pulling or merging if you haven't got
+your own work into good shape and committed it locally (see also
+linkgit:git-stash[1]).
+
+But novices can make this mistake, and 'git pull' and 'git merge'
+will stop without doing anything when local uncommitted changes
+overlap with files that 'git pull'/'git merge' may need to update.
+
+Also, to avoid unrelated changes in the recorded commit, 'git
+pull' and 'git merge' abort if there are any changes registered
+in the index relative to the contents of the `HEAD` commit.
+(One exception is when the changed index entries are already in
+the same state that would result from the merge anyway.)
+
+If all named commits are already ancestors of `HEAD`, 'git merge'
+will exit early with the message "Already up-to-date."
+
 include::merge-strategies.txt[]
 
 
@@ -70,17 +92,9 @@ HOW MERGE WORKS
 ---------------
 
 A merge is always between the current `HEAD` and one or more
-commits (usually, branch head or tag), and the index file must
-match the tree of `HEAD` commit (i.e. the contents of the last commit)
-when it starts out.  In other words, `git diff --cached HEAD` must
-report no changes.  (One exception is when the changed index
-entries are already in the same state that would result from
-the merge anyway.)
-
-Three kinds of merge can happen:
+commits (usually, branch head or tag).
 
-* The merged commit is already contained in `HEAD`. This is the
-  simplest case, called "Already up-to-date."
+Two kinds of merge can happen:
 
 * `HEAD` is already contained in the merged commit. This is the
   most common case especially when invoked from 'git pull':
-- 
1.6.6
Previous: Junio C HamanoNext: Thomas Rast
Message 23 of 46 in “Documentation/git-merge: reword references to "remote" and "pull"”
  1. 1/2 Documentation/git-merge: reword references to "remote" and "pull"Thomas Rast, Jan 7, 2010
  2. 2/2 Documentation: warn prominently against merging with dirty treesThomas Rast, Jan 7, 2010
  3. 3/2 Documentation/git-merge: format full commands in typewriter fontThomas Rast, Jan 7, 2010
  4. Jonathan NiederJan 7, 2010
  5. Junio C HamanoJan 7, 2010
  6. Junio C HamanoJan 7, 2010
  7. 0/4 Documentation style fixesThomas Rast, Jan 10, 2010
  8. 1/4 Documentation/git-merge: reword references to "remote" and "pull"Thomas Rast, Jan 10, 2010
  9. Jonathan NiederJan 10, 2010
  10. Thomas RastJan 10, 2010
  11. Documentation: merge: use MERGE_HEAD to refer to the remote branchJonathan Nieder, Jan 23, 2010
  12. 2/4 Documentation: warn prominently against merging with dirty treesThomas Rast, Jan 10, 2010
  13. Jonathan NiederJan 10, 2010
  14. Junio C HamanoJan 10, 2010
  15. Thomas RastJan 10, 2010
  16. Jonathan NiederJan 11, 2010
  17. Junio C HamanoJan 11, 2010
  18. Jonathan NiederJan 11, 2010
  19. 0/6 Re: Documentation: warn prominently against merging with dirty treesJonathan Nieder, Jan 11, 2010
  20. 1/6 Documentation: clarify one-line description for mergeJonathan Nieder, Jan 11, 2010
  21. 2/6 Documentation: merge: add an overviewJonathan Nieder, Jan 11, 2010
  22. Junio C HamanoJan 11, 2010
  23. 4/6 Documentation: emphasize when git merge terminates earlyJonathan Nieder, Jan 11, 2010
  24. Thomas RastJan 11, 2010
  25. 5/6 Documentation: merge: add a section about fast-forwardJonathan Nieder, Jan 11, 2010
  26. 6/6 Documentation: tweak How Merge WorksJonathan Nieder, Jan 11, 2010
  27. Thomas RastJan 11, 2010
  28. Petr BaudisJan 13, 2010
  29. Junio C HamanoJan 13, 2010
  30. 3/4 Documentation: format full commands in typewriter fontThomas Rast, Jan 10, 2010
  31. Jonathan NiederJan 10, 2010
  32. Thomas RastJan 10, 2010
  33. Thomas RastJan 10, 2010
  34. Junio C HamanoJan 10, 2010
  35. Thomas RastJan 10, 2010
  36. 1/2 More missed dashed 'git-cmd' formsThomas Rast, Jan 10, 2010
  37. 2/2 More missed `code snippets`Thomas Rast, Jan 10, 2010
  38. Documentation: show-files is now called git-ls-filesThomas Rast, Jan 10, 2010
  39. Junio C HamanoJan 18, 2010
  40. Thomas RastJan 19, 2010
  41. Jonathan NiederJan 19, 2010
  42. Junio C HamanoJan 10, 2010
  43. Jonathan NiederJan 10, 2010
  44. 1/2 Documentation: git gc packs refs by default nowJonathan Nieder, Jan 10, 2010
  45. 2/2 Documentation: tiny git config manual tweaksJonathan Nieder, Jan 10, 2010
  46. Thomas RastJan 10, 2010

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.