Skip to content

Commit 409f066

Browse files
bk2204gitster
authored andcommitted
docs: explain why reverts are not always applied on merge
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 merged, 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5065ce4 commit 409f066

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Documentation/gitfaq.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,27 @@ original merge base.
273273
As a consequence, if you want to merge two long-lived branches repeatedly, it's
274274
best to always use a regular merge commit.
275275

276+
[[merge-two-revert-one]]
277+
If I make a change on two branches but revert it on one, why does the merge of those branches include the change?::
278+
By default, when Git does a merge, it uses a strategy called the recursive
279+
strategy, which does a fancy three-way merge. In such a case, when Git
280+
performs the merge, it considers exactly three points: the two heads and a
281+
third point, called the _merge base_, which is usually the common ancestor of
282+
those commits. Git does not consider the history or the individual commits
283+
that have happened on those branches at all.
284+
+
285+
As a result, if both sides have a change and one side has reverted that change,
286+
the result is to include the change. This is because the code has changed on
287+
one side and there is no net change on the other, and in this scenario, Git
288+
adopts the change.
289+
+
290+
If this is a problem for you, you can do a rebase instead, rebasing the branch
291+
with the revert onto the other branch. A rebase in this scenario will revert
292+
the change, because a rebase applies each individual commit, including the
293+
revert. Note that rebases rewrite history, so you should avoid rebasing
294+
published branches unless you're sure you're comfortable with that. See the
295+
NOTES section in linkgit:git-rebase[1] for more details.
296+
276297
Hooks
277298
-----
278299

0 commit comments

Comments
 (0)