blob: 9ee083c415a27dc499b75031d49df9e3f3856ec0 [file] [log] [blame]
Junio C Hamano8389b522006-01-28 23:15:24 -08001git-rerere(1)
2=============
3
4NAME
5----
Junio C Hamanoc3f0baa2007-01-18 15:53:37 -08006git-rerere - Reuse recorded resolution of conflicted merges
Junio C Hamano8389b522006-01-28 23:15:24 -08007
8SYNOPSIS
9--------
Martin von Zweigbergk7791a1d2011-07-01 22:38:26 -040010[verse]
Phil Hord3e7a1df2012-03-08 16:08:50 -050011'git rerere' ['clear'|'forget' <pathspec>|'diff'|'remaining'|'status'|'gc']
Junio C Hamano8389b522006-01-28 23:15:24 -080012
13DESCRIPTION
14-----------
15
Stephen Boydc97038d2009-06-13 11:20:00 -070016In a workflow employing relatively long lived topic branches,
17the developer sometimes needs to resolve the same conflicts over
Junio C Hamano8389b522006-01-28 23:15:24 -080018and over again until the topic branches are done (either merged
19to the "release" branch, or sent out and accepted upstream).
20
Stephen Boydc97038d2009-06-13 11:20:00 -070021This 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 Hamano8389b522006-01-28 23:15:24 -080025
Junio C Hamano11c57e62008-01-14 15:10:38 -080026[NOTE]
Michael J Gruber02944cc2009-07-28 16:42:15 +020027You need to set the configuration variable rerere.enabled in order to
Junio C Hamano11c57e62008-01-14 15:10:38 -080028enable this command.
29
Junio C Hamanocda2d3c2006-12-08 13:03:12 -080030
31COMMANDS
32--------
33
Thomas Rast0b444cd2010-01-10 00:33:00 +010034Normally, 'git rerere' is run without arguments or user-intervention.
Junio C Hamanocda2d3c2006-12-08 13:03:12 -080035However, it has several commands that allow it to interact with
36its working state.
37
38'clear'::
39
Phil Hord3e7a1df2012-03-08 16:08:50 -050040Reset the metadata used by rerere if a merge resolution is to be
Thomas Rast0b444cd2010-01-10 00:33:00 +010041aborted. Calling 'git am [--skip|--abort]' or 'git rebase [--skip|--abort]'
Jonathan Nieder483bc4f2008-06-30 13:56:34 -050042will automatically invoke this command.
Junio C Hamanocda2d3c2006-12-08 13:03:12 -080043
Michael J Gruber2c640342010-07-05 15:15:20 +020044'forget' <pathspec>::
45
Phil Hord3e7a1df2012-03-08 16:08:50 -050046Reset the conflict resolutions which rerere has recorded for the current
Johannes Sixt5d2c3b02011-03-01 14:21:05 +010047conflict in <pathspec>.
Michael J Gruber2c640342010-07-05 15:15:20 +020048
Junio C Hamanocda2d3c2006-12-08 13:03:12 -080049'diff'::
50
Phil Hord3e7a1df2012-03-08 16:08:50 -050051Display diffs for the current state of the resolution. It is
Junio C Hamanocda2d3c2006-12-08 13:03:12 -080052useful for tracking what has changed while the user is resolving
53conflicts. Additional arguments are passed directly to the system
Jonathan Nieder2fd02c92008-07-03 00:55:07 -050054'diff' command installed in PATH.
Junio C Hamanocda2d3c2006-12-08 13:03:12 -080055
56'status'::
57
Phil Hord3e7a1df2012-03-08 16:08:50 -050058Print 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 Hamanocda2d3c2006-12-08 13:03:12 -080065
66'gc'::
67
Phil Hord3e7a1df2012-03-08 16:08:50 -050068Prune records of conflicted merges that
Stephen Boydc97038d2009-06-13 11:20:00 -070069occurred 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
Nguyễn Thái Ngọc Duyda0005b2015-03-11 16:32:45 -040072`gc.rerereUnresolved` and `gc.rerereResolved` configuration
Stephen Boydc97038d2009-06-13 11:20:00 -070073variables respectively.
Junio C Hamanocda2d3c2006-12-08 13:03:12 -080074
75
Junio C Hamano8389b522006-01-28 23:15:24 -080076DISCUSSION
77----------
78
Stephen Boydc97038d2009-06-13 11:20:00 -070079When your topic branch modifies an overlapping area that your
Junio C Hamano8389b522006-01-28 23:15:24 -080080master 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------------
94 $ git checkout topic
Nicolas Pitrec14261e2007-01-14 22:44:18 -050095 $ git merge master
Junio C Hamano8389b522006-01-28 23:15:24 -080096
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
Jeff King6cf378f2012-04-26 04:51:57 -0400104marked with `+`. Then you can test the result to make sure your
Junio C Hamano8389b522006-01-28 23:15:24 -0800105work-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
Jeff King6cf378f2012-04-26 04:51:57 -0400109commit `+`, and when your work in the topic branch is finally
Junio C Hamano8389b522006-01-28 23:15:24 -0800110ready, pull the topic branch into master, and/or ask the
111upstream to pull from you. By that time, however, the master or
Jeff King6cf378f2012-04-26 04:51:57 -0400112the upstream might have been advanced since the test merge `+`,
Junio C Hamano8389b522006-01-28 23:15:24 -0800113in which case the final commit graph would look like this:
114
115------------
116 $ git checkout topic
Nicolas Pitrec14261e2007-01-14 22:44:18 -0500117 $ git merge master
Junio C Hamano8389b522006-01-28 23:15:24 -0800118 $ ... work on both topic and master branches
119 $ git checkout master
Nicolas Pitrec14261e2007-01-14 22:44:18 -0500120 $ git merge topic
Junio C Hamano8389b522006-01-28 23:15:24 -0800121
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------------
139 $ git checkout topic
Nicolas Pitrec14261e2007-01-14 22:44:18 -0500140 $ git merge master
Junio C Hamano8389b522006-01-28 23:15:24 -0800141 $ git reset --hard HEAD^ ;# rewind the test merge
142 $ ... work on both topic and master branches
143 $ git checkout master
Nicolas Pitrec14261e2007-01-14 22:44:18 -0500144 $ git merge topic
Junio C Hamano8389b522006-01-28 23:15:24 -0800145
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
Stephen Boydc97038d2009-06-13 11:20:00 -0700154commits marked with `*`. However, this conflict is often the
Junio C Hamano8389b522006-01-28 23:15:24 -0800155same conflict you resolved when you created the test merge you
Thomas Rast0b444cd2010-01-10 00:33:00 +0100156blew away. 'git rerere' helps you resolve this final
Junio C Hamano8389b522006-01-28 23:15:24 -0800157conflicted merge using the information from your earlier hand
158resolve.
159
Thomas Rast0b444cd2010-01-10 00:33:00 +0100160Running the 'git rerere' command immediately after a conflicted
Junio C Hamano8389b522006-01-28 23:15:24 -0800161automerge records the conflicted working tree files, with the
162usual conflict markers `<<<<<<<`, `=======`, and `>>>>>>>` in
163them. Later, after you are done resolving the conflicts,
Thomas Rast0b444cd2010-01-10 00:33:00 +0100164running 'git rerere' again will record the resolved state of these
Junio C Hamano8389b522006-01-28 23:15:24 -0800165files. Suppose you did this when you created the test merge of
166master into the topic branch.
167
Stephen Boydc97038d2009-06-13 11:20:00 -0700168Next time, after seeing the same conflicted automerge,
Thomas Rast0b444cd2010-01-10 00:33:00 +0100169running 'git rerere' will perform a three-way merge between the
Junio C Hamano8389b522006-01-28 23:15:24 -0800170earlier conflicted automerge, the earlier manual resolution, and
Stephen Boydc97038d2009-06-13 11:20:00 -0700171the current conflicted automerge.
Junio C Hamano8389b522006-01-28 23:15:24 -0800172If this three-way merge resolves cleanly, the result is written
Stephen Boydc97038d2009-06-13 11:20:00 -0700173out to your working tree file, so you do not have to manually
Thomas Rast0b444cd2010-01-10 00:33:00 +0100174resolve it. Note that 'git rerere' leaves the index file alone,
Junio C Hamano8389b522006-01-28 23:15:24 -0800175so you still need to do the final sanity checks with `git diff`
Thomas Rast0b444cd2010-01-10 00:33:00 +0100176(or `git diff -c`) and 'git add' when you are satisfied.
Junio C Hamano8389b522006-01-28 23:15:24 -0800177
Thomas Rast0b444cd2010-01-10 00:33:00 +0100178As a convenience measure, 'git merge' automatically invokes
179'git rerere' upon exiting with a failed automerge and 'git rerere'
Stephen Boydc97038d2009-06-13 11:20:00 -0700180records the hand resolve when it is a new conflict, or reuses the earlier hand
Thomas Rast0b444cd2010-01-10 00:33:00 +0100181resolve when it is not. 'git commit' also invokes 'git rerere'
Stephen Boydc97038d2009-06-13 11:20:00 -0700182when 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 Hamano8389b522006-01-28 23:15:24 -0800185
Stephen Boydc97038d2009-06-13 11:20:00 -0700186In our example, when you do the test merge, the manual
Junio C Hamano8389b522006-01-28 23:15:24 -0800187resolution is recorded, and it will be reused when you do the
Stephen Boydc97038d2009-06-13 11:20:00 -0700188actual merge later with the updated master and topic branch, as long
189as the recorded resolution is still applicable.
Junio C Hamano8389b522006-01-28 23:15:24 -0800190
Thomas Rast0b444cd2010-01-10 00:33:00 +0100191The information 'git rerere' records is also used when running
192'git rebase'. After blowing away the test merge and continuing
Junio C Hamano8389b522006-01-28 23:15:24 -0800193development 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
Stephen Boydc97038d2009-06-13 11:20:00 -0700207you could run `git rebase master topic`, to bring yourself
208up-to-date before your topic is ready to be sent upstream.
209This would result in falling back to a three-way merge, and it
210would conflict the same way as the test merge you resolved earlier.
Thomas Rast0b444cd2010-01-10 00:33:00 +0100211'git rerere' will be run by 'git rebase' to help you resolve this
Junio C Hamano8389b522006-01-28 23:15:24 -0800212conflict.
213
Junio C Hamano8389b522006-01-28 23:15:24 -0800214GIT
215---
Christian Couder9e1f0a82008-06-06 09:07:32 +0200216Part of the linkgit:git[1] suite