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