Skip to content

Commit

Permalink
Convert undo-merge figures to Sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
ben committed Jul 10, 2014
1 parent a595be1 commit 2ecd7a7
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
Binary file modified book/07-git-tools/images/undomerge-reset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified book/07-git-tools/images/undomerge-revert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified book/07-git-tools/images/undomerge-revert2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified book/07-git-tools/images/undomerge-revert3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified book/07-git-tools/images/undomerge-start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions book/07-git-tools/sections/undoing-merges.asc
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ Git calls this operation a ``revert'', and in this particular scenario, you'd in
[source,shell]
----
$ git revert -m 1 HEAD
[master b1d8379] Revert "Merge branch 'topic-branch'"
[master b1d8379] Revert "Merge branch 'topic'"
----

The `-m 1` flag indicates which parent is the ``mainline'' and should be kept.
When you invoke a merge into `HEAD` (`git merge topic-branch`), the new commit has two parents: the first one is `HEAD` (`C6`), and the second is the tip of the branch being merged in (`C4`).
When you invoke a merge into `HEAD` (`git merge topic`), the new commit has two parents: the first one is `HEAD` (`C6`), and the second is the tip of the branch being merged in (`C4`).
In this case, we want to undo all the changes introduced by merging in parent #2 (`C4`), while keeping all the content from parent #1 (`C6`).

The history with the revert commit looks like this:
Expand All @@ -55,16 +55,16 @@ The history with the revert commit looks like this:
image::../images/undomerge-revert.png[History after `git revert -m 1`.]

The new commit `^M` has exactly the same contents as `C6`, so starting from here it's as if the merge never happened, except that the now-unmerged commits are still in `HEAD`'s history.
Git will get confused if you try to merge `topic-branch` into `master` again:
Git will get confused if you try to merge `topic` into `master` again:

[source,shell]
----
$ git merge topic-branch
$ git merge topic
Already up-to-date.
----

There's nothing in `topic-branch` that isn't already reachable from `master`.
What's worse, if you add work to `topic-branch` and merge again, Git will only bring in the changes _since_ the reverted merge:
There's nothing in `topic` that isn't already reachable from `master`.
What's worse, if you add work to `topic` and merge again, Git will only bring in the changes _since_ the reverted merge:

.History with a bad merge
image::../images/undomerge-revert2.png[History with a bad merge.]
Expand All @@ -74,12 +74,12 @@ The best way around this is to un-revert the original merge, since now you want
[source,shell]
----
$ git revert ^M
[master 09f0126] Revert "Revert "Merge branch 'topic-branch'""
$ git merge topic-branch
[master 09f0126] Revert "Revert "Merge branch 'topic'""
$ git merge topic
----

.History after re-merging a reverted merge
image::../images/undomerge-revert3.png[History after re-merging a reverted merge.]

In this example, `M` and `^M` cancel out.
`^^M` effectively merges in the changes from `C3` and `C4`, and `C8` merges in the changes from `C7`, so now `topic-branch` is fully merged.
`^^M` effectively merges in the changes from `C3` and `C4`, and `C8` merges in the changes from `C7`, so now `topic` is fully merged.
Binary file modified diagram-source/progit.sketch/Data
Binary file not shown.
2 changes: 1 addition & 1 deletion diagram-source/progit.sketch/metadata
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>Menlo-Bold</string>
</array>
<key>length</key>
<integer>8589340</integer>
<integer>9132068</integer>
<key>version</key>
<integer>37</integer>
</dict>
Expand Down

0 comments on commit 2ecd7a7

Please sign in to comment.