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