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?