Code

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