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

*Non*-interactive squash a range ?

From
DDavid <bouncingcats@gmail.com>
Date
Jul 3, 2010, 13:38 UTC
Message-ID
<AANLkTimTx2dVlK9KKi1nZpOadwDcfyzhE8nffCyK1Sqm@mail.gmail.com>

Thanks for the awesome git. I have a basic question. I am subscribed to this list.

Having successfully used rebase -i to squash, I wonder about some method to *non*-interactively squash a sequence of intermediate commits. On a local experimental branch.

Lets say the starting point is this branch named "uglybranch" with HEAD=J
    E---F---G---H---I---J  <uglybranch>
where commit G added a previously untracked file.
My desired result is this:
      ------------------K  <cleanbranch>
     /
    E---F---G---H---I---J  <uglybranch>
where K and J are identical worktrees.
I've used rebase -i as follows:
 $ git checkout uglybranch
 $ git checkout -b cleanbranch
 $ git rebase -i E
 # used interactive editor to squash all F..J onto E to produce K, on
cleanbranch only, uglybranch is not changed.

This gives exactly the result I want, in particular the file added at G is preserved, but the drawback is that the method is needlessly interactive. I want a foolproof non-interactive method that achieves the same result. Namely squashing *all* the commits in the range F..J

I tried this which seems to work:
 $ git checkout uglybranch
 $ git checkout -b cleanbranch
 $ git reset --mixed E          # worktree same as uglybranch
 $ git add .                    # adds any untracked files
 $ git commit -a                # -a detects any removed files

So I'm thinking of using that method in a script. Have I overlooked anything? Is there a better way?

Next: Johannes Sixt
Message 1 of 3 in “*Non*-interactive squash a range ?”
  1. DavidJul 3, 2010
  2. Johannes SixtJul 5, 2010
  3. Daniele SegatoJul 5, 2010

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.