@@ -158,6 +158,142 @@ When you are ready to ask for the merge of your code:
158
158
and not master. Github can not automatically determine the branch
159
159
to merge into.
160
160
161
+ Rebasing a Pull Request (PR)
162
+ ============================
163
+
164
+ When working on a PR, changes may occur in the parent branch (usually master).
165
+ This can lead to conflict with changes in your branch. The conflicts can be
166
+ trivial: for example both the parent branch and your branch add an entry to
167
+ the top of `CHANGELOG `. Git can not unambiguously tell what to with both
168
+ changes (should one go above the other? if so, which order? should it try to
169
+ merge them?) so it declares the branches can not be merged
170
+ cleanly. Github can only automatically merge PR without conflicts, so you will
171
+ need to manually 'rebase'. This is the process of updating your branch with
172
+ upstream changes, and resolving conflicts.
173
+
174
+ In git, rebasing is a mild form of re-writing history: it effectively forwards
175
+ all your commits to the updated upstream commit. For a much more detailed
176
+ explanation (with pictures!) see `this nice write up
177
+ <http://git-scm.com/book/en/Git-Branching-Rebasing> `. The numpy team has also
178
+ `documented how to do this
179
+ <http://docs.scipy.org/doc/numpy/dev/gitwash/development_workflow.html#rebasing-on-master> `
180
+ In general, re-writing history, particularly published history, is considered
181
+ bad practice, but in this case it is very useful.
182
+
183
+ The following example assumes that the remote of _your_ github
184
+ repository is called `github ` and the remote of the official
185
+ repository is called `matplotlib `.
186
+
187
+ The first step is to make sure that your local copy of the upstream repository is
188
+ up-to-date::
189
+
190
+ $ git fetch matplotlib
191
+
192
+ This updates your local copy of the repository, but does not change any files
193
+ in your working copy. Next, switch to the branch that you want to update::
194
+
195
+ $ git checkout backend_plt_refactor
196
+
197
+ You are now ready to start the rebase of your branch onto the target
198
+ parent branch, in this case `matplotlib/master ` ::
199
+
200
+ $ git rebase matplotlib/master
201
+
202
+ and git will then give a bunch of feed back::
203
+
204
+ First, rewinding head to replay your work on top of it...
205
+ Applying: first steps to extract FigureManager* and friends from pyplot
206
+ Applying: split backend_qt4 into two parts, with and without Gcf
207
+ ...
208
+ Applying: pep8 clean up on backend_gtk3.py
209
+ Using index info to reconstruct a base tree...
210
+ M lib/matplotlib/backends/backend_gtk3.py
211
+ Falling back to patching base and 3-way merge...
212
+ Auto-merging lib/matplotlib/backends/backend_gtk3.py
213
+ CONFLICT (content): Merge conflict in lib/matplotlib/backends/backend_gtk3.py
214
+ Failed to merge in the changes.
215
+ Patch failed at 0013 pep8 clean up on backend_gtk3.py
216
+ The copy of the patch that failed is found in:
217
+ /home/tcaswell/other_source/matplotlib/.git/rebase-apply/patch
218
+
219
+ When you have resolved this problem, run "git rebase --continue".
220
+ If you prefer to skip this patch, run "git rebase --skip" instead.
221
+ To check out the original branch and stop rebasing, run "git rebase --abort".
222
+
223
+ A number of commits could be cleanly applied to
224
+ the tip of `matplotlib/master `, however, git eventually hits a commit
225
+ that had conflicts. In this case in the file
226
+ `lib/matplotlib/backends/backend_gtk3.py `. For more verbose information run ::
227
+
228
+ $ git status
229
+
230
+ You are currently rebasing branch 'backend_plt_refactor' on 'e6f8993'.
231
+ (fix conflicts and then run "git rebase --continue")
232
+ (use "git rebase --skip" to skip this patch)
233
+ (use "git rebase --abort" to check out the original branch)
234
+
235
+ Unmerged paths:
236
+ (use "git reset HEAD <file>..." to unstage)
237
+ (use "git add <file>..." to mark resolution)
238
+
239
+ both modified: lib/matplotlib/backends/backend_gtk3.py
240
+
241
+ no changes added to commit (use "git add" and/or "git commit -a")
242
+
243
+ This tells you exactly where the conflict is and provides some advice
244
+ on how to proceed. Opening up the file in question, you will see
245
+ blocks that look something like this::
246
+
247
+ <<<<<<< HEAD
248
+ =======
249
+ self.__dict__.clear() # Is this needed? Other backends don't have it.
250
+ >>>>>>> pep8 clean up on backend_gtk3.py
251
+
252
+ The block of code between `<<<<<<< ` and `======= ` is the code on the
253
+ target branch (in this case nothing) and the code between `======= `
254
+ and `>>>>>>> ` is the code on your branch. The rest of the code is the
255
+ same between the two branches. You need to determine how to resolve the
256
+ conflict (in this case, the code on HEAD is correct). Once you have
257
+ resolved all the conflicts, `add ` the file to the index::
258
+
259
+ $ git add lib/matplotlib/backends/backend_gtk3.py
260
+
261
+ Repeat this for all of the files that have conflicts. When you are done with
262
+ that you can check the status::
263
+
264
+ $ git status
265
+ rebase in progress; onto e6f8993
266
+ You are currently rebasing branch 'backend_plt_refactor' on 'e6f8993'.
267
+ (all conflicts fixed: run "git rebase --continue")
268
+
269
+ Changes to be committed:
270
+ (use "git reset HEAD <file>..." to unstage)
271
+
272
+ modified: lib/matplotlib/backends/backend_gtk3.py
273
+
274
+ which shows us that we have resolved all of the conflicts with this
275
+ commit and can continue::
276
+
277
+ $ git rebase --continue
278
+
279
+ You now iterate the until you have made it through all of the commits
280
+ which have conflicts. Once you have successfully rebased your branch,
281
+ be sure to re-run the tests to make sure everything is still working
282
+ properly.
283
+
284
+ Your branch is now rebased, however, because of the way git
285
+ determines the hash of each commit, it now shares no commits with your
286
+ old branch published on github so you can not push to that branch as
287
+ you would when simply adding commits. In order to publish your newly
288
+ rebased (and tested!) branch you need to use the `--force ` flag::
289
+
290
+ $ git push --force github
291
+
292
+ which will _replace_ all of the commits under your branch on github
293
+ with the new versions of the commit.
294
+
295
+ Congratulations, you have rebased your branch!
296
+
161
297
Staying up to date with changes in the central repository
162
298
=========================================================
163
299
0 commit comments