3

We are working in a team where we had local branches with everyone working their own branch and we had committed few branches and merged with --squash.

Now we have to delete those branches that are merged in in 'staging' branch.

The issue is when we command 'git diff' to see our branches, it shows that all commits that are squashed are unmerged.

We are geting unmerged branches using:

git branch -a --no-merged staging | grep github | cut -d/ -f3 > /not-gihub.txt   

Thanks!

Angelfirenze
  • 99
  • 1
  • 14
Raza Hussain
  • 762
  • 8
  • 18
  • 1
    It's not immediately clear to me if this is your real question, but: `git merge --squash` does *not* create a merge commit, and (as it says right in the documentation) does not update `MERGE_HEAD` either. That is, it merely uses the merge machinery to create merged *files*, but does not create any merged *history*. – torek Sep 24 '14 at 06:43
  • 1
    @torek Could you please tell me the way,that we can use identify exact branches those are not merged including squashed commits? – Raza Hussain Sep 24 '14 at 06:54
  • 1
    `--no-merged` will find branches that are not merged: you're doing that part right. The key is that a "squash merge" is *not* a merge. The name "squash merge" is highly misleading! – torek Sep 24 '14 at 07:02
  • 1
    @torek Is there any way to solve this issue Or we have to manually verify the code differences? – Raza Hussain Sep 24 '14 at 07:07
  • 2
    You're probably stuck with manually verifying the code. You can automate this to some extent by having git produce a real merge and comparing the resulting trees. For instance, if you think branch `S` was squash-merged into branch `B`, you could make a temporary merge of `S`-into-`B` (perhaps using "detached HEAD" mode, even) and compare the resulting trees. If someone resolved merge conflicts, though, this won't completely automate your task. – torek Sep 24 '14 at 07:11
  • I think I have a problem similar to this one. I accidentally pushed the MERGE_HEAD file up to Github and it overwrote a duplicate of many files into my repository. I can't figure out how to delete it and return to what I had. I'm trying 'git rebase', but I'm not getting anywhere. – Angelfirenze Jan 04 '15 at 12:35

1 Answers1

0

What you're observing is the documented behavior: from man git-merge,

--squash

Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit, move the HEAD, or record $GIT_DIR/MERGE_HEAD (to cause the next git commit command to create a merge commit).

The ancestry information is not recorded into Git, so you'll have to get the information of whether a branch is merged by looking at the code (probably manually).

Community
  • 1
  • 1
Matthieu Moy
  • 15,151
  • 5
  • 38
  • 65