git/list[1] front-page[2] threads[3] people[4] search[5] about
 

RFC: git squash

From
JMJulius Musseau <julius@mergebase.com>
Date
Feb 23, 2018, 03:41 UTC
Message-ID
<CAA7Zk=tMMPE_Ov6cSJuzgYwWmTuMTSd_909c5JY3a2k5KFzHgQ@mail.gmail.com>
Hi, Git Developers,

Thanks for your help regarding my earlier email (trying to break git pull --rebase).

I just wanted to warn you all that my first attempt at a patch is imminent. I'm working on a "git squash" command. Here's a quick summary:

------ git squash [<commit>]

Squashes <commit>..HEAD into a single commit. Replaces HEAD with the result. If not specified, <commit> defaults to the current branch's upstream (a.k.a. @{upstream}).

Rationale:

This command provides an intuitive mechanism for in-place squash that doesn't drop dirty merge results.

We call this an in-place squash because the state of all files and directories at HEAD does not change. Only the ancestory of HEAD changes: its (only) parent becomes the merge-base of <commit> and HEAD, removing all intermediate commits.

Alternatives:
- "git merge --squash master" correctly preserves dirty merge results,
but it's tricky to achieve an in-place squash with this command, since
it requires the following sequence of commands (these assume the
current branch is "feature" and we want to squash it relative to
"master"):
    git checkout $(git merge-base HEAD master)
    git merge --squash feature
    git commit
    git branch -f feature
    git checkout feature
- "git rebase --interactive HEAD~N" with commits set to "squash" (or
"fixup") is very popular in industry.  But it has some tricky edge
cases: drops dirty merge results, can run into conflicts, and can be
confusing if HEAD~N spans any merges (including clean merges).
-----

I expect I'll have the patch finished this weekend, and ready for everyone to look at by Monday (Feb 26th).

Note:  I'm not 100% sure "git rebase --interactive" would drop dirty
merge results (e.g., the dirty parts from conflict-resolving merges).
That's speculation on my part.  I'll confirm this before I finish and
submit the patch.
yours sincerely,
Julius Musseau
Next: Junio C Hamano
Message 1 of 4 in “RFC: git squash”
  1. Julius MusseauFeb 23, 2018
  2. Junio C HamanoFeb 23, 2018
  3. Julius MusseauFeb 23, 2018
  4. Junio C HamanoFeb 23, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.