threads / discuss / 14734

git merge --squash isn't "marked as a merge"??

Subject: git merge --squash isn't "marked as a merge"??

## tl;dr

2 messages between Jul 29, 2008 and Jul 29, 2008.

replies: 1people: 2as markdown or json

Peter Valdemar Mørch (Lists)· Jul 29, 2008, 07:49 UTC · lore
Newbie alert:

I have a feature branch where I have N tiny commits with sloppy/private commit messages. Being able to have private commits was the main reason I'm using git (as a frontend to svn).

Today the feature is in a "good" state, and I want to merge it into a main branch, showing a single commit with a well phrased message for all the world to see. So I:

$ git checkout master $ git merge --squash feature $ git commit -F wellphrased.msg

Now I was expecting that: $ git merge feature would do nothing (I already did a merge!). But it pulls in all the sloppy commits and messages from "feature"!

Of course now I could continue with a new branch made like this: $ git checkout -b feature2 master and continue working privately on feature2 again. Then I'll end up with feature..feature47 before I'm done. Each with its own segment of my private history. A real mess.

Can I continue on feature somehow so I privately can "git log" and see all my messy commits (both before and after the "git merge --squash") and then regularly "git merge" and/or "git merge --squash" back and forth between "feature" and "master" as I deem appropriate?

I'm guessing that if the --squash *did* put in a "merge arrow" (setting a "parent" of the commit to the head of feature) thereby allowing merge to not do anything, then git log would also follow feature's sloppy history too. They go together as a pair. Is that right? Testing this:

git help merge says about --squash:
> Produce the working tree and index state as if a real merge happened,
> but do not actually make a commit or move the HEAD, nor record
> $GIT_DIR/MERGE_HEAD to cause the next git commit command to create a
> merge commit.

So I tried "git merge --squash feature", then set up .git/MERGE_HEAD to the same contents as .git/refs/heads/feature and then "git commit". This produced the same result as "git merge" without --squash including all the sloppy messages.

SO: It seems to me I cannot continuously merge "feature" to "master" in 
chunks with "--squash" as I would like. Is that right? Is my desire 
fundamentally misguided, and is there A Better Way?
Peter
-- 
Peter Valdemar Mørch
http://www.morch.com
Junio C Hamano· Jul 29, 2008, 08:53 UTC · re: Peter Valdemar Mørch (Lists) · lore

Re: git merge --squash isn't "marked as a merge"??

"Peter Valdemar Mørch (Lists)"  <4ux6as402@sneakemail.com> writes:
> Newbie alert:
>
> I have a feature branch where I have N tiny commits with sloppy/private
> commit messages....

Probably you would want to step back and _think_ why you want to squash in the first place. I suspect the answer would lead to a better use of the available set of tools, such as "use 'rebase -i' to clean up the original history and then 'merge' (without squash) it or 'rebase' it".

← back to recent threads