@@ -358,13 +358,24 @@ To avoid merges as per the [No-Merge Policy](#no-merge-policy), you may want to
358
358
to ensure that Git doesn't create merge commits when `git pull`ing, without
359
359
needing to pass `--ff-only` or `--rebase` every time.
360
360
361
- You can also `git push --force-with-lease` from master to keep your fork's master in sync with
362
- upstream .
361
+ You can also `git push --force-with-lease` from master to double-check that your
362
+ feature branches are in sync with their state on the Github side .
363
363
364
364
## Advanced Rebasing
365
365
366
366
### Squash your commits
367
367
368
+ "Squashing" commits into each other causes them to be merged into a single
369
+ commit. Both the upside and downside of this is that it simplifies the history.
370
+ On the one hand, you lose track of the steps in which changes were made, but
371
+ the history becomes easier to work with.
372
+
373
+ If there are no conflicts and you are just squashing to clean up the history,
374
+ use `git rebase --interactive --keep-base master`. This keeps the fork point
375
+ of your PR the same, making it easier to review the diff of what happened
376
+ across your rebases.
377
+
378
+ Squashing can also be useful as part of conflict resolution.
368
379
If your branch contains multiple consecutive rewrites of the same code, or if
369
380
the rebase conflicts are extremely severe, you can use
370
381
`git rebase --interactive master` to gain more control over the process. This
@@ -375,17 +386,12 @@ Alternatively, you can sacrifice the commit history like this:
375
386
376
387
```
377
388
# squash all the changes into one commit so you only have to worry about conflicts once
378
- git rebase -i $(git merge- base master HEAD) # and squash all changes along the way
389
+ git rebase -i --keep- base master # and squash all changes along the way
379
390
git rebase master
380
391
# fix all merge conflicts
381
392
git rebase --continue
382
393
```
383
394
384
- "Squashing" commits into each other causes them to be merged into a single
385
- commit. Both the upside and downside of this is that it simplifies the history.
386
- On the one hand, you lose track of the steps in which changes were made, but
387
- the history becomes easier to work with.
388
-
389
395
You also may want to squash just the last few commits together, possibly
390
396
because they only represent "fixups" and not real changes. For example,
391
397
`git rebase --interactive HEAD~2` will allow you to edit the two commits only.
0 commit comments