Skip to content

Commit fcadf96

Browse files
authored
squashing: recommend --keep-base when squashing without a conflict (rust-lang#2157)
1 parent 1f851c0 commit fcadf96

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/git.md

+14-8
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,24 @@ To avoid merges as per the [No-Merge Policy](#no-merge-policy), you may want to
358358
to ensure that Git doesn't create merge commits when `git pull`ing, without
359359
needing to pass `--ff-only` or `--rebase` every time.
360360
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.
363363
364364
## Advanced Rebasing
365365
366366
### Squash your commits
367367
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.
368379
If your branch contains multiple consecutive rewrites of the same code, or if
369380
the rebase conflicts are extremely severe, you can use
370381
`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:
375386
376387
```
377388
# 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
379390
git rebase master
380391
# fix all merge conflicts
381392
git rebase --continue
382393
```
383394
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-
389395
You also may want to squash just the last few commits together, possibly
390396
because they only represent "fixups" and not real changes. For example,
391397
`git rebase --interactive HEAD~2` will allow you to edit the two commits only.

0 commit comments

Comments
 (0)