# *Non*-interactive squash a range ?

3 messages from 2010-07-03 to 2010-07-05. Participants: David, Johannes Sixt, Daniele Segato.
Thread: https://gitlist.dev/t/24275

## David, 2010-07-03 13:38

Subject: *Non*-interactive squash a range ?
Message-ID: <AANLkTimTx2dVlK9KKi1nZpOadwDcfyzhE8nffCyK1Sqm@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimTx2dVlK9KKi1nZpOadwDcfyzhE8nffCyK1Sqm%40mail.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?

```

## Johannes Sixt, 2010-07-05 06:27

Subject: Re: *Non*-interactive squash a range ?
Message-ID: <4C317B4B.3070100@viscovery.net>
URL: https://gitlist.dev/e/4C317B4B.3070100%40viscovery.net
In-Reply-To: <AANLkTimTx2dVlK9KKi1nZpOadwDcfyzhE8nffCyK1Sqm@mail.gmail.com>

```
Am 7/3/2010 15:38, schrieb David:
> 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, 2010-07-05 07:00

Subject: Re: *Non*-interactive squash a range ?
Message-ID: <AANLkTimVgEUofsrZ0SnCXdW3zMF0SOfup4lQBXwWXXP7@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimVgEUofsrZ0SnCXdW3zMF0SOfup4lQBXwWXXP7%40mail.gmail.com
In-Reply-To: <AANLkTimTx2dVlK9KKi1nZpOadwDcfyzhE8nffCyK1Sqm@mail.gmail.com>

```
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.

[...]

> 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

```
