@@ -172,6 +172,73 @@ When you are ready to ask for someone to review your code and consider a merge:
172
172
pull request message. This is still a good way of getting some preliminary
173
173
code review.
174
174
175
+ Update your pull request
176
+ ========================
177
+
178
+ Often, you'll want to update your contribution based on the feedback in the
179
+ pull request. While it's possible to simply push additional commits to your
180
+ feature branch, this will clutter the history. Not every step in the
181
+ development of a feature is worth recording. In contrast, a clean history
182
+ with one or a few thematically separated commits helps to keep it more
183
+ understandable. Most small features will do with a single commit.
184
+
185
+ There are two techniques to achieve this.
186
+
187
+ Ammend an existing commit
188
+ Use this if you have don't need to keep track of the incremental changes
189
+ to your feature.
190
+ Squash multiple commits
191
+ Use this to cleanup the history when you've already made multiple commits
192
+ to your feature branch.
193
+
194
+ Both techniques rewrite the history of your feature branch. While generally
195
+ one has to be careful with rewriting the history, this is intended and
196
+ perfectly fine for commits that are currently on your feature branch only.
197
+ Commits already merged into master should never be touched.
198
+
199
+ The following descriptions apply the techniques to the last commits. This is
200
+ slightly simpler than the general case, but the most common from when
201
+ updating pull requests.
202
+
203
+ Ammending the last commit
204
+ -------------------------
205
+ You have pushed a single commit for your feature and now want to update it.
206
+
207
+ On your feature branch::
208
+
209
+ # make your updates
210
+ git add [your_changed_files]
211
+ git commit --amend --no-edit
212
+ git push --force
213
+
214
+ `--amend ` means that the last commit will be rewritten to include the changes
215
+ instead of creating a new commit. If `--no-edit ` is used the existing commit
216
+ message will be used. Otherwise, you'll be asked if you want to modify the
217
+ commit message.
218
+
219
+ Since you are overwriting the last commit with the rewritten version, you
220
+ have to add `--force ` to the push command. Github will automatically update
221
+ your pull request after the push.
222
+
223
+ Squashing the last N commits
224
+ ----------------------------
225
+ You have N commits in your feature branch (e.g. N=3) and want to turn them
226
+ into a single commit.
227
+
228
+ On your feature branch::
229
+
230
+ git reset --soft HEAD~3
231
+ git commit
232
+ git push --force
233
+
234
+ The soft reset rolls back the commits, but keeps all their changes staged.
235
+ `HEAD~3 ` means: Go back three commits before `HEAD `. Adapt the number by
236
+ to the number of commits you want to join.
237
+
238
+ Since all changes are staged, you can now commit them into a single new commit.
239
+ After that you have to force-push your changes.
240
+
241
+
175
242
Some other things you might want to do
176
243
======================================
177
244
0 commit comments