Documentation / git-rerere.txton commit sha1_name: warning ambiguous refs. (84a9b58)
   1git-rerere(1)
   2=============
   3
   4NAME
   5----
   6git-rerere - Reuse recorded resolve
   7
   8SYNOPSIS
   9--------
  10'git-rerere'
  11
  12
  13DESCRIPTION
  14-----------
  15
  16In a workflow that employs relatively long lived topic branches,
  17the developer sometimes needs to resolve the same conflict over
  18and over again until the topic branches are done (either merged
  19to the "release" branch, or sent out and accepted upstream).
  20
  21This command helps this process by recording conflicted
  22automerge results and corresponding hand-resolve results on the
  23initial manual merge, and later by noticing the same automerge
  24results and applying the previously recorded hand resolution.
  25
  26[NOTE]
  27You need to create `$GIT_DIR/rr-cache` directory to enable this
  28command.
  29
  30DISCUSSION
  31----------
  32
  33When your topic branch modifies overlapping area that your
  34master branch (or upstream) touched since your topic branch
  35forked from it, you may want to test it with the latest master,
  36even before your topic branch is ready to be pushed upstream:
  37
  38------------
  39              o---*---o topic
  40             /
  41    o---o---o---*---o---o master
  42------------
  43
  44For such a test, you need to merge master and topic somehow.
  45One way to do it is to pull master into the topic branch:
  46
  47------------
  48        $ git checkout topic
  49        $ git pull . master
  50
  51              o---*---o---+ topic
  52             /           /
  53    o---o---o---*---o---o master
  54------------
  55
  56The commits marked with `*` touch the same area in the same
  57file; you need to resolve the conflicts when creating the commit
  58marked with `+`.  Then you can test the result to make sure your
  59work-in-progress still works with what is in the latest master.
  60
  61After this test merge, there are two ways to continue your work
  62on the topic.  The easiest is to build on top of the test merge
  63commit `+`, and when your work in the topic branch is finally
  64ready, pull the topic branch into master, and/or ask the
  65upstream to pull from you.  By that time, however, the master or
  66the upstream might have been advanced since the test merge `+`,
  67in which case the final commit graph would look like this:
  68
  69------------
  70        $ git checkout topic
  71        $ git pull . master
  72        $ ... work on both topic and master branches
  73        $ git checkout master
  74        $ git pull . topic
  75
  76              o---*---o---+---o---o topic
  77             /           /         \
  78    o---o---o---*---o---o---o---o---+ master
  79------------
  80
  81When your topic branch is long-lived, however, your topic branch
  82would end up having many such "Merge from master" commits on it,
  83which would unnecessarily clutter the development history.
  84Readers of the Linux kernel mailing list may remember that Linus
  85complained about such too frequent test merges when a subsystem
  86maintainer asked to pull from a branch full of "useless merges".
  87
  88As an alternative, to keep the topic branch clean of test
  89merges, you could blow away the test merge, and keep building on
  90top of the tip before the test merge:
  91
  92------------
  93        $ git checkout topic
  94        $ git pull . master
  95        $ git reset --hard HEAD^ ;# rewind the test merge
  96        $ ... work on both topic and master branches
  97        $ git checkout master
  98        $ git pull . topic
  99
 100              o---*---o-------o---o topic
 101             /                     \
 102    o---o---o---*---o---o---o---o---+ master
 103------------
 104
 105This would leave only one merge commit when your topic branch is
 106finally ready and merged into the master branch.  This merge
 107would require you to resolve the conflict, introduced by the
 108commits marked with `*`.  However, often this conflict is the
 109same conflict you resolved when you created the test merge you
 110blew away.  `git-rerere` command helps you to resolve this final
 111conflicted merge using the information from your earlier hand
 112resolve.
 113
 114Running `git-rerere` command immediately after a conflicted
 115automerge records the conflicted working tree files, with the
 116usual conflict markers `<<<<<<<`, `=======`, and `>>>>>>>` in
 117them.  Later, after you are done resolving the conflicts,
 118running `git-rerere` again records the resolved state of these
 119files.  Suppose you did this when you created the test merge of
 120master into the topic branch.
 121
 122Next time, running `git-rerere` after seeing a conflicted
 123automerge, if the conflict is the same as the earlier one
 124recorded, it is noticed and a three-way merge between the
 125earlier conflicted automerge, the earlier manual resolution, and
 126the current conflicted automerge is performed by the command.
 127If this three-way merge resolves cleanly, the result is written
 128out to your working tree file, so you would not have to manually
 129resolve it.  Note that `git-rerere` leaves the index file alone,
 130so you still need to do the final sanity checks with `git diff`
 131(or `git diff -c`) and `git update-index` when you are
 132satisfied.
 133
 134As a convenience measure, `git-merge` automatically invokes
 135`git-rerere` when it exits with a failed automerge, which
 136records it if it is a new conflict, or reuses the earlier hand
 137resolve when it is not.  `git-commit` also invokes `git-rerere`
 138when recording a merge result.  What this means is that you do
 139not have to do anything special yourself (Note: you still have
 140to create `$GIT_DIR/rr-cache` directory to enable this command).
 141
 142In our example, when you did the test merge, the manual
 143resolution is recorded, and it will be reused when you do the
 144actual merge later with updated master and topic branch, as long
 145as the earlier resolution is still applicable.
 146
 147The information `git-rerere` records is also used when running
 148`git-rebase`.  After blowing away the test merge and continuing
 149development on the topic branch:
 150
 151------------
 152              o---*---o-------o---o topic
 153             /
 154    o---o---o---*---o---o---o---o   master
 155
 156        $ git rebase master topic
 157
 158                                  o---*---o-------o---o topic
 159                                 /
 160    o---o---o---*---o---o---o---o   master
 161------------
 162
 163you could run `git rebase master topic`, to keep yourself
 164up-to-date even before your topic is ready to be sent upstream.
 165This would result in falling back to three-way merge, and it
 166would conflict the same way the test merge you resolved earlier.
 167`git-rerere` is run by `git rebase` to help you resolve this
 168conflict.
 169
 170
 171Author
 172------
 173Written by Junio C Hamano <junkio@cox.net>
 174
 175GIT
 176---
 177Part of the gitlink:git[7] suite