@@ -166,29 +166,149 @@ C/C++ extensions
166
166
Rebase a Pull Request
167
167
----------------------
168
168
169
- When working on PR it is possible for other changes to get merged into
170
- the parent branch that conflict with your branch. The conflict can be
171
- trivial, for example both the parent branch and you branch add an
172
- entry to the top of `CHANGELOG `. Git can not unambiguously tell what
173
- to with both changes (should one go above the other? if so, which
174
- order? should it try to merge them?) so it gives up and declare the
175
- branches can not be merged cleanly. If you were the branches at the
176
- command line you could do an interactive merge where git pauses half
177
- way through to give you a chance to resolve the conflicts by hand,
178
- however using github almost all of the merges back into the parent
179
- branches are done via the web-interface, so only PRs which will
180
- cleanly merged will be accepted. If this happens to your PR, one of
181
- the developers will ask you to 'rebase' your branch which is the
182
- process by which you resolve the conflicts between your branch and
183
- the parent branch.
169
+ When working on a PR it is possible for other changes to get merged
170
+ into the parent branch that conflict with changes on your branch. The
171
+ conflicts can be trivial, for example both the parent branch and your
172
+ branch add an entry to the top of `CHANGELOG `. Git can not
173
+ unambiguously tell what to with both changes (should one go above the
174
+ other? if so, which order? should it try to merge them?) so it gives
175
+ up and declare the branches can not be merged cleanly. If you were
176
+ the branches at the command line you could do an interactive merge
177
+ where git pauses half way through to give you a chance to resolve the
178
+ conflicts by hand, however using github almost all of the merges back
179
+ into the parent branches are done via the web-interface, so only PRs
180
+ which will cleanly merged will be accepted. If this happens to your
181
+ PR, one of the developers will ask you to 'rebase' your branch which
182
+ is the process by which you resolve the conflicts between your branch
183
+ and the parent branch.
184
184
185
185
In git rebasing is a mild form of re-writing history, as it
186
186
effectively transplants where your branch from where you intially
187
187
forked of off the parent branch to some other point. For a much more
188
- detailed explanation (with pictures!) see
189
- http://git-scm.com/book/en/Git-Branching-Rebasing. In general,
190
- re-writing history (particularly published history) is considered very
191
- bad, but in this case is very useful.
188
+ detailed explanation (with pictures!) see `this nice write up
189
+ <http://git-scm.com/book/en/Git-Branching-Rebasing> `. In general,
190
+ re-writing history, particularly published history, is considered
191
+ bad form, but in this case it is very useful.
192
+
193
+ The following example assumes that the remote of _your_ github
194
+ repository is called `github ` and the remote of the official
195
+ repository is called `upstream `.
196
+
197
+ The first step is to make sure that your local copy of the upstream repository is
198
+ up-to-date::
199
+
200
+ $ git fetch upstream
201
+
202
+ which updates your local copy of the repository, but does not change any files
203
+ in your working copy. Next, switch to the branch that you want to rebase::
204
+
205
+ $ git checkout backend_plt_refactor
206
+
207
+ You are now ready to start the rebase of your branch onto the target
208
+ parent branch, in this case `upstream/master ` ::
209
+
210
+ $ git rebase upstream/master
211
+
212
+ and git will then give a bunch of feed back::
213
+
214
+ First, rewinding head to replay your work on top of it...
215
+ Applying: first steps to extract FigureManager* and friends from pyplot
216
+ Applying: split backend_qt4 into two parts, with and without Gcf
217
+ Applying: split backend_qt4agg into two parts.
218
+ Applying: Added a demo-file to show how to use the FigureManager classes to
219
+ Applying: removed un-needed import of Gcf
220
+ Applying: pep8 on backend_gtk.py
221
+ Applying: pep8 clean up in backend_gdk
222
+ Applying: removed un-needed Gcf import
223
+ Applying: split backend_gcf into two parts,
224
+ Applying: pep8 on backend_gtkagg.py
225
+ Applying: split backend_gktagg.py in to two parts
226
+ Applying: updated exclude list
227
+ Applying: pep8 clean up on backend_gtk3.py
228
+ Using index info to reconstruct a base tree...
229
+ M lib/matplotlib/backends/backend_gtk3.py
230
+ Falling back to patching base and 3-way merge...
231
+ Auto-merging lib/matplotlib/backends/backend_gtk3.py
232
+ CONFLICT (content): Merge conflict in lib/matplotlib/backends/backend_gtk3.py
233
+ Failed to merge in the changes.
234
+ Patch failed at 0013 pep8 clean up on backend_gtk3.py
235
+ The copy of the patch that failed is found in:
236
+ /home/tcaswell/other_source/matplotlib/.git/rebase-apply/patch
237
+
238
+ When you have resolved this problem, run "git rebase --continue".
239
+ If you prefer to skip this patch, run "git rebase --skip" instead.
240
+ To check out the original branch and stop rebasing, run "git rebase --abort".
241
+
242
+ A number of commits could be cleanly applied to
243
+ the tip of `upstream/master `, however, git eventualy hit a commit
244
+ that had conflicts. In this case in the file
245
+ `lib/matplotlib/backends/backend_gtk3.py `. For more verbose information run ::
246
+
247
+ $ git status
248
+
249
+ You are currently rebasing branch 'backend_plt_refactor' on 'e6f8993'.
250
+ (fix conflicts and then run "git rebase --continue")
251
+ (use "git rebase --skip" to skip this patch)
252
+ (use "git rebase --abort" to check out the original branch)
253
+
254
+ Unmerged paths:
255
+ (use "git reset HEAD <file>..." to unstage)
256
+ (use "git add <file>..." to mark resolution)
257
+
258
+ both modified: lib/matplotlib/backends/backend_gtk3.py
259
+
260
+ no changes added to commit (use "git add" and/or "git commit -a")
261
+
262
+ This exactly where the conflict is and some advice on how to proceed. Opening
263
+ up the file in question, you will see blocks that look something like this::
264
+
265
+ <<<<<<< HEAD
266
+ =======
267
+ self.__dict__.clear() # Is this needed? Other backends don't have it.
268
+ >>>>>>> pep8 clean up on backend_gtk3.py
269
+
270
+ The block of code between `<<<<<<< ` and `======= ` is the code on the
271
+ target branch (in this case nothing) and the code between `======= `
272
+ and `>>>>>>> ` is the code on your branch. The rest of the code is the
273
+ same between the two branches. You need to determine how to resolve the
274
+ conflict (in this case, the code on HEAD is correct). Once you have
275
+ resolved all the conflicts, `add ` the file to the index::
276
+
277
+ $ git add lib/matplotlib/backends/backend_gtk3.py
278
+
279
+ Repeat this for all of the files that have conflicts. When you are done with
280
+ that we can check the status::
281
+
282
+ $ git status
283
+ rebase in progress; onto e6f8993
284
+ You are currently rebasing branch 'backend_plt_refactor' on 'e6f8993'.
285
+ (all conflicts fixed: run "git rebase --continue")
286
+
287
+ Changes to be committed:
288
+ (use "git reset HEAD <file>..." to unstage)
289
+
290
+ modified: lib/matplotlib/backends/backend_gtk3.py
291
+
292
+ which shows us that we have resolved all of the conflicts with this
293
+ commit and can continue::
294
+
295
+ $ git rebase --continue
296
+
297
+ You now iterate the until you have made it through all of the commits
298
+ which have conflicts.
299
+
300
+ Your branch is now rebased, however, because of the way git determines
301
+ the hash of each commit, it now shares no commits with your old branch
302
+ published on github so you can not push to that branch as you would when
303
+ simply adding commits. In order to publish your newly re-based branch you need to
304
+ use the `--force ` flag::
305
+
306
+ $ git push --force github
307
+
308
+ which will _replace_ all of the commits under your branch on github
309
+ with the new versions of the commit.
310
+
311
+ Congratulations, you have re-based your branch!
192
312
193
313
194
314
Style guide
0 commit comments