Skip to content

Commit f8dfcef

Browse files
committed
add docs on updating PRs using git
1 parent 98bfb96 commit f8dfcef

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

doc/devel/gitwash/development_workflow.rst

+65
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,71 @@ When you are ready to ask for someone to review your code and consider a merge:
172172
pull request message. This is still a good way of getting some preliminary
173173
code review.
174174

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 to be recorded. In contrast, a clean
182+
history with one or a few thematically separted commits helps to keep it
183+
more 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 updates to your feature branch.
197+
198+
The following descriptions apply the techniques to the last commits. This is
199+
slightly simpler than the general case, but the most common from when
200+
updating pull requests.
201+
202+
Ammending the last commit
203+
-------------------------
204+
You have pushed a single commit for your feature and now want to update it.
205+
206+
On your feature branch::
207+
208+
# make your updates
209+
git commit --all --amend --no-edit
210+
git push --force
211+
212+
`--amend` means that the last commit will be rewritten to include the changes
213+
instead of creating a new commit. If `--no-edit` is used the existing commit
214+
message will be used. Otherwise, you'll be asked if you want to modify the
215+
commit message.
216+
217+
Since you are overwriting the last commit with the rewritten version, you
218+
have to add `--force` to the push command. Github will automatically update
219+
your pull request after the push.
220+
221+
Squashing the last N commits
222+
----------------------------
223+
You have N commits in your feature branch (e.g. N=3) and want to turn them
224+
into a single commit.
225+
226+
On your feature branch::
227+
228+
git reset --soft HEAD~3
229+
git commit
230+
git push --force
231+
232+
The soft reset rolls back the commits, but keeps all their changes staged.
233+
`HEAD~3` means: Go back three commits before `HEAD`. Adapt the number by
234+
to the number of commits you want to join.
235+
236+
Since all changes are staged, you can now commit them into a single new commit.
237+
After that you have to force-push your changes.
238+
239+
175240
Some other things you might want to do
176241
======================================
177242

0 commit comments

Comments
 (0)