threads / discuss / 24275

*Non*-interactive squash a range ?

Subject: *Non*-interactive squash a range ?

## tl;dr

3 messages between Jul 3, 2010 and Jul 5, 2010.

replies: 2people: 3as markdown or json

David· Jul 3, 2010, 13:38 UTC · lore

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?

Johannes Sixt· Jul 5, 2010, 06:27 UTC · re: David · lore

Re: *Non*-interactive squash a range ?

Am 7/3/2010 15:38, schrieb David:
Show 9 quoted lines
> 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?
Use 'reset --soft' instead of 'reset --mixed' followed by 'add .'.
-- Hannes
Daniele Segato· Jul 5, 2010, 07:00 UTC · re: David · lore

Re: *Non*-interactive squash a range ?

On Sat, Jul 3, 2010 at 3:38 PM, David <bouncingcats@gmail.com> wrote:
> 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.
[...]
Show 7 quoted lines
> My desired result is this:
>
>      ------------------K  <cleanbranch>
>     /
>    E---F---G---H---I---J  <uglybranch>
>
> where K and J are identical worktrees.
why don't you:
git checkout -b cleanbranch E~
git merge --squash J

regards, Daniele Segato

← back to recent threads