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

[PATCH 2/3] docs: explain why reverts are not always applied on merge

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Sep 12, 2020, 20:48 UTC
Message-ID
<20200912204824.2824106-3-sandals@crustytoothpaste.net>
In-Reply-To
<20200912204824.2824106-1-sandals@crustytoothpaste.net>

A common scenario is for a user to apply a change to one branch and cherry-pick it into another, then later revert it in the first branch. This results in the change being present when the two branches are merge, which is confusing to many users.

We already have documentation for how this works in `git merge`, but it is clear from the frequency with which this is asked that it's hard to grasp. We also don't explain to users that they are better off doing a rebase in this case, which will do what they intended. Let's add an entry to the FAQ telling users what's happening and advising them to use rebase here.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 Documentation/gitfaq.txt | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
diff --git a/Documentation/gitfaq.txt b/Documentation/gitfaq.txt
index 550f4e30d6..154f0cce54 100644
--- a/Documentation/gitfaq.txt
+++ b/Documentation/gitfaq.txt
@@ -274,6 +274,25 @@ original merge base.
 As a consequence, if you want to merge two long-running branches, it's best to
 always use a regular merge commit.
 
+[[merge-two-revert-one]]
+If I make a change on two branches but revert it on one, why does the merge of those branches include the change?::
+	By default, when Git does a merge, it uses a strategy called the recursive
+	strategy, which does a fancy three-way merge.  In such a case, when Git
+	performs the merge, it considers exactly three points: the two heads and a
+	third point, called the _merge base_, which is usually the common ancestor of
+	those commits.  Git does not consider the history or the individual commits
+	that have happened on those branches at all.
++
+As a result, if both sides have a change and one side has reverted that change,
+the result is to include the change.  This is because the code has changed on
+one side and there is no net change on the other, and in this scenario, Git
+adopts the change.
++
+If this is a problem for you, you can do a rebase instead, rebasing the branch
+with the revert onto the other branch.  A rebase in this scenario will revert
+the change, because a rebase applies each individual commit, including the
+revert.
+
 Hooks
 -----
 
Previous: Martin ÅgrenNext: Martin Ågren
Message 4 of 13 in “FAQ entries for merges and modified files”
  1. 0/3 FAQ entries for merges and modified filesbrian m. carlson, Sep 12, 2020
  2. 3/3 docs: explain how to deal with files that are always modifiedbrian m. carlson, Sep 12, 2020
  3. Martin ÅgrenSep 13, 2020
  4. 2/3 docs: explain why reverts are not always applied on mergebrian m. carlson, Sep 12, 2020
  5. Martin ÅgrenSep 13, 2020
  6. 1/3 docs: explain why squash merges are broken with long-running branchesbrian m. carlson, Sep 12, 2020
  7. Martin ÅgrenSep 13, 2020
  8. brian m. carlsonSep 13, 2020
  9. Junio C HamanoSep 12, 2020
  10. 0/3 FAQ entries for merges and modified filesbrian m. carlson, Sep 20, 2020
  11. 2/3 docs: explain why reverts are not always applied on mergebrian m. carlson, Sep 20, 2020
  12. 1/3 docs: explain why squash merges are broken with long-running branchesbrian m. carlson, Sep 20, 2020
  13. 3/3 docs: explain how to deal with files that are always modifiedbrian m. carlson, Sep 20, 2020

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.