blob: 992b469270c004f4ce7c4223dbc3b84239a14a5f [file] [log] [blame]
Junio C Hamano40f2f8d2006-02-07 08:04:391git-rerere(1)
2=============
3
4NAME
5----
Junio C Hamano7c73c662007-01-19 00:37:506git-rerere - Reuse recorded resolution of conflicted merges
Junio C Hamano40f2f8d2006-02-07 08:04:397
8SYNOPSIS
9--------
Junio C Hamano15567bc2011-07-23 00:51:5910[verse]
Junio C Hamanocf9c7732022-10-28 18:56:0611'git rerere' [clear | forget <pathspec>... | diff | status | remaining | gc]
Junio C Hamano40f2f8d2006-02-07 08:04:3912
13DESCRIPTION
14-----------
15
Junio C Hamano25e7ba62009-06-14 01:03:2216In a workflow employing relatively long lived topic branches,
17the developer sometimes needs to resolve the same conflicts over
Junio C Hamano40f2f8d2006-02-07 08:04:3918and over again until the topic branches are done (either merged
19to the "release" branch, or sent out and accepted upstream).
20
Junio C Hamano25e7ba62009-06-14 01:03:2221This command assists the developer in this process by recording
22conflicted automerge results and corresponding hand resolve results
23on the initial manual merge, and applying previously recorded
24hand resolutions to their corresponding automerge results.
Junio C Hamano40f2f8d2006-02-07 08:04:3925
Junio C Hamano0e47b232008-01-15 08:31:1026[NOTE]
Junio C Hamano2ba14712019-04-25 10:12:2727You need to set the configuration variable `rerere.enabled` in order to
Junio C Hamano0e47b232008-01-15 08:31:1028enable this command.
29
Junio C Hamanoe7935c42006-12-13 21:32:1730
31COMMANDS
32--------
33
Junio C Hamano1aa40d22010-01-21 17:46:4334Normally, 'git rerere' is run without arguments or user-intervention.
Junio C Hamanoe7935c42006-12-13 21:32:1735However, it has several commands that allow it to interact with
36its working state.
37
38'clear'::
39
Junio C Hamanoc55452a2012-03-14 23:05:1140Reset the metadata used by rerere if a merge resolution is to be
Junio C Hamano1aa40d22010-01-21 17:46:4341aborted. Calling 'git am [--skip|--abort]' or 'git rebase [--skip|--abort]'
Junio C Hamanofce7c7e2008-07-02 03:06:3842will automatically invoke this command.
Junio C Hamanoe7935c42006-12-13 21:32:1743
Junio C Hamano3e3aa812010-07-05 23:25:2344'forget' <pathspec>::
45
Junio C Hamanoc55452a2012-03-14 23:05:1146Reset the conflict resolutions which rerere has recorded for the current
Junio C Hamanod2c978f2011-03-20 19:42:2247conflict in <pathspec>.
Junio C Hamano3e3aa812010-07-05 23:25:2348
Junio C Hamanoe7935c42006-12-13 21:32:1749'diff'::
50
Junio C Hamanoc55452a2012-03-14 23:05:1151Display diffs for the current state of the resolution. It is
Junio C Hamanoe7935c42006-12-13 21:32:1752useful for tracking what has changed while the user is resolving
53conflicts. Additional arguments are passed directly to the system
Junio C Hamanoba4b9282008-07-06 05:20:3154'diff' command installed in PATH.
Junio C Hamanoe7935c42006-12-13 21:32:1755
56'status'::
57
Junio C Hamanoc55452a2012-03-14 23:05:1158Print paths with conflicts whose merge resolution rerere will record.
59
60'remaining'::
61
62Print paths with conflicts that have not been autoresolved by rerere.
63This includes paths whose resolutions cannot be tracked by rerere,
64such as conflicting submodules.
Junio C Hamanoe7935c42006-12-13 21:32:1765
66'gc'::
67
Junio C Hamanoc55452a2012-03-14 23:05:1168Prune records of conflicted merges that
Junio C Hamano25e7ba62009-06-14 01:03:2269occurred a long time ago. By default, unresolved conflicts older
70than 15 days and resolved conflicts older than 60
71days are pruned. These defaults are controlled via the
Junio C Hamano322c6242015-03-23 21:32:4672`gc.rerereUnresolved` and `gc.rerereResolved` configuration
Junio C Hamano25e7ba62009-06-14 01:03:2273variables respectively.
Junio C Hamanoe7935c42006-12-13 21:32:1774
75
Junio C Hamano40f2f8d2006-02-07 08:04:3976DISCUSSION
77----------
78
Junio C Hamano25e7ba62009-06-14 01:03:2279When your topic branch modifies an overlapping area that your
Junio C Hamano40f2f8d2006-02-07 08:04:3980master branch (or upstream) touched since your topic branch
81forked from it, you may want to test it with the latest master,
82even before your topic branch is ready to be pushed upstream:
83
84------------
85 o---*---o topic
86 /
87 o---o---o---*---o---o master
88------------
89
90For such a test, you need to merge master and topic somehow.
91One way to do it is to pull master into the topic branch:
92
93------------
Junio C Hamanoc9f11c22019-07-10 02:54:0494$ git switch topic
Junio C Hamanoedd2b0a2007-01-15 06:12:4595$ git merge master
Junio C Hamano40f2f8d2006-02-07 08:04:3996
97 o---*---o---+ topic
98 / /
99 o---o---o---*---o---o master
100------------
101
102The commits marked with `*` touch the same area in the same
103file; you need to resolve the conflicts when creating the commit
Junio C Hamanob76a6862012-05-02 22:02:46104marked with `+`. Then you can test the result to make sure your
Junio C Hamano40f2f8d2006-02-07 08:04:39105work-in-progress still works with what is in the latest master.
106
107After this test merge, there are two ways to continue your work
108on the topic. The easiest is to build on top of the test merge
Junio C Hamanob76a6862012-05-02 22:02:46109commit `+`, and when your work in the topic branch is finally
Junio C Hamano40f2f8d2006-02-07 08:04:39110ready, pull the topic branch into master, and/or ask the
111upstream to pull from you. By that time, however, the master or
Junio C Hamanob76a6862012-05-02 22:02:46112the upstream might have been advanced since the test merge `+`,
Junio C Hamano40f2f8d2006-02-07 08:04:39113in which case the final commit graph would look like this:
114
115------------
Junio C Hamanoc9f11c22019-07-10 02:54:04116$ git switch topic
Junio C Hamanoedd2b0a2007-01-15 06:12:45117$ git merge master
Junio C Hamano40f2f8d2006-02-07 08:04:39118$ ... work on both topic and master branches
Junio C Hamanoc9f11c22019-07-10 02:54:04119$ git switch master
Junio C Hamanoedd2b0a2007-01-15 06:12:45120$ git merge topic
Junio C Hamano40f2f8d2006-02-07 08:04:39121
122 o---*---o---+---o---o topic
123 / / \
124 o---o---o---*---o---o---o---o---+ master
125------------
126
127When your topic branch is long-lived, however, your topic branch
128would end up having many such "Merge from master" commits on it,
129which would unnecessarily clutter the development history.
130Readers of the Linux kernel mailing list may remember that Linus
131complained about such too frequent test merges when a subsystem
132maintainer asked to pull from a branch full of "useless merges".
133
134As an alternative, to keep the topic branch clean of test
135merges, you could blow away the test merge, and keep building on
136top of the tip before the test merge:
137
138------------
Junio C Hamanoc9f11c22019-07-10 02:54:04139$ git switch topic
Junio C Hamanoedd2b0a2007-01-15 06:12:45140$ git merge master
Junio C Hamano40f2f8d2006-02-07 08:04:39141$ git reset --hard HEAD^ ;# rewind the test merge
142$ ... work on both topic and master branches
Junio C Hamanoc9f11c22019-07-10 02:54:04143$ git switch master
Junio C Hamanoedd2b0a2007-01-15 06:12:45144$ git merge topic
Junio C Hamano40f2f8d2006-02-07 08:04:39145
146 o---*---o-------o---o topic
147 / \
148 o---o---o---*---o---o---o---o---+ master
149------------
150
151This would leave only one merge commit when your topic branch is
152finally ready and merged into the master branch. This merge
153would require you to resolve the conflict, introduced by the
Junio C Hamano25e7ba62009-06-14 01:03:22154commits marked with `*`. However, this conflict is often the
Junio C Hamano40f2f8d2006-02-07 08:04:39155same conflict you resolved when you created the test merge you
Junio C Hamano1aa40d22010-01-21 17:46:43156blew away. 'git rerere' helps you resolve this final
Junio C Hamano40f2f8d2006-02-07 08:04:39157conflicted merge using the information from your earlier hand
158resolve.
159
Junio C Hamano1aa40d22010-01-21 17:46:43160Running the 'git rerere' command immediately after a conflicted
Junio C Hamano40f2f8d2006-02-07 08:04:39161automerge records the conflicted working tree files, with the
162usual conflict markers `<<<<<<<`, `=======`, and `>>>>>>>` in
163them. Later, after you are done resolving the conflicts,
Junio C Hamano1aa40d22010-01-21 17:46:43164running 'git rerere' again will record the resolved state of these
Junio C Hamano40f2f8d2006-02-07 08:04:39165files. Suppose you did this when you created the test merge of
166master into the topic branch.
167
Junio C Hamano25e7ba62009-06-14 01:03:22168Next time, after seeing the same conflicted automerge,
Junio C Hamano1aa40d22010-01-21 17:46:43169running 'git rerere' will perform a three-way merge between the
Junio C Hamano40f2f8d2006-02-07 08:04:39170earlier conflicted automerge, the earlier manual resolution, and
Junio C Hamano25e7ba62009-06-14 01:03:22171the current conflicted automerge.
Junio C Hamano40f2f8d2006-02-07 08:04:39172If this three-way merge resolves cleanly, the result is written
Junio C Hamano25e7ba62009-06-14 01:03:22173out to your working tree file, so you do not have to manually
Junio C Hamano1aa40d22010-01-21 17:46:43174resolve it. Note that 'git rerere' leaves the index file alone,
Junio C Hamano40f2f8d2006-02-07 08:04:39175so you still need to do the final sanity checks with `git diff`
Junio C Hamano1aa40d22010-01-21 17:46:43176(or `git diff -c`) and 'git add' when you are satisfied.
Junio C Hamano40f2f8d2006-02-07 08:04:39177
Junio C Hamano1aa40d22010-01-21 17:46:43178As a convenience measure, 'git merge' automatically invokes
179'git rerere' upon exiting with a failed automerge and 'git rerere'
Junio C Hamano25e7ba62009-06-14 01:03:22180records the hand resolve when it is a new conflict, or reuses the earlier hand
Junio C Hamano1aa40d22010-01-21 17:46:43181resolve when it is not. 'git commit' also invokes 'git rerere'
Junio C Hamano25e7ba62009-06-14 01:03:22182when committing a merge result. What this means is that you do
183not have to do anything special yourself (besides enabling
184the rerere.enabled config variable).
Junio C Hamano40f2f8d2006-02-07 08:04:39185
Junio C Hamano25e7ba62009-06-14 01:03:22186In our example, when you do the test merge, the manual
Junio C Hamano40f2f8d2006-02-07 08:04:39187resolution is recorded, and it will be reused when you do the
Junio C Hamano25e7ba62009-06-14 01:03:22188actual merge later with the updated master and topic branch, as long
189as the recorded resolution is still applicable.
Junio C Hamano40f2f8d2006-02-07 08:04:39190
Junio C Hamano1aa40d22010-01-21 17:46:43191The information 'git rerere' records is also used when running
192'git rebase'. After blowing away the test merge and continuing
Junio C Hamano40f2f8d2006-02-07 08:04:39193development on the topic branch:
194
195------------
196 o---*---o-------o---o topic
197 /
198 o---o---o---*---o---o---o---o master
199
200$ git rebase master topic
201
202 o---*---o-------o---o topic
203 /
204 o---o---o---*---o---o---o---o master
205------------
206
Junio C Hamano25e7ba62009-06-14 01:03:22207you could run `git rebase master topic`, to bring yourself
Junio C Hamano88bf5712017-09-10 08:39:23208up to date before your topic is ready to be sent upstream.
Junio C Hamano25e7ba62009-06-14 01:03:22209This would result in falling back to a three-way merge, and it
210would conflict the same way as the test merge you resolved earlier.
Junio C Hamano1aa40d22010-01-21 17:46:43211'git rerere' will be run by 'git rebase' to help you resolve this
Junio C Hamano40f2f8d2006-02-07 08:04:39212conflict.
213
Junio C Hamano980e61e2018-09-17 22:45:52214[NOTE] 'git rerere' relies on the conflict markers in the file to
215detect the conflict. If the file already contains lines that look the
216same as lines with conflict markers, 'git rerere' may fail to record a
217conflict resolution. To work around this, the `conflict-marker-size`
218setting in linkgit:gitattributes[5] can be used.
219
Junio C Hamano40f2f8d2006-02-07 08:04:39220GIT
221---
Junio C Hamanof7c042d2008-06-06 22:50:53222Part of the linkgit:git[1] suite