git-machete icon indicating copy to clipboard operation
git-machete copied to clipboard

Question: how to conveniently merge all HEADs?

Open LeeAlephium opened this issue 3 years ago • 7 comments

I'm trying to combine all the HEADs of my branches but I'm not sure there's some git machete idiomatic way to do this. It's particularly useful for being github agnostic, where you want to have one large chunk of changes, and you can also verify that the patches merge more nicely down the line. For now I'm checking out one branch and git merge --no-commit for each branch HEAD.

Thank you!

LeeAlephium avatar Aug 08 '22 17:08 LeeAlephium

Hi there, for clarity... could you provide your .git/machete file? Ofc you can redact branch names if confidential.

I suppose it has multiple branches attached directly under the root branch (like main), and not a long chain of branches one under another?

PawelLipski avatar Aug 08 '22 19:08 PawelLipski

Not my file but this is a good way to understand for sure!

master
  f1a
    f2a
      f3a
    f2b
  g1a

I would then want to create a new branch "h1a" which is a combination of f3a, f2b, and g1a (since they are the HEADs of the branches) :) Hope that helps!

LeeAlephium avatar Aug 08 '22 19:08 LeeAlephium

Huh I've got a déjà vu... a similar thing has been suggested by my colleague @kgadek recently.

Our observations/conclusions were that:

  1. Currently there's no support for anything similar in git-machete CLI nor in the IntelliJ plugin.
  2. Syntax in .git/machete that would provide support for this feature, for a branch layout like: image could look like that: image (with .. selected so that it cannot start a valid branch name.
  3. The higher-level problem is, however, that this task is somewhat orthogonal to what git-machete does. It's more of a matter of file-modification-aware octopus merge missing from git (as of v2.37.1, at least). The octopus merge strategy, used for merging 3+ branches (git merge A B [C [D ...]]) doesn't resolve modifications to the same file as smoothly as the default ort strategy does.
  4. Some workaround would be to just indeed, run a loop over branches and merge them one by one (i.e. always merging just 2 branches, with the default ort strategy). Or your variation, with --no-commit (but that's still, 2 branches merged with ort). I guess Konrad could share his own version of the script if needed ;)
  5. There exists a lesfurets/git-octopus project, which kind of seems to implement (3.), but it's pretty opinionated and doesn't seem to be maintained anymore.

So yeah... that's the state of affairs! I wouldn't completely exclude adding this feature into git-machete... but I believe it might be better for a separate tool to exist for this purpose. git-machete is already much more ~bloated~ feature-rich than I ever expected it'll be 😅

PawelLipski avatar Aug 08 '22 19:08 PawelLipski

Oh I never intended to imply to add more to git-machete! I agree it already does a lot. Your answer then tells me I need to make a small script most likely :) I don't want any fancy merge strategy, I just want a tool that can repeat the merge process every time I want to create this new single branch... Now that I think about it though I think it's as simple as:

git switch -c h1a && git merge f3a f2b g1a

The only thing left is to easily get those leaves!

Maybe it's within machete's scope to add such a function? git machete leaves returns a list of leaves?

LeeAlephium avatar Aug 08 '22 20:08 LeeAlephium

Maybe it's within machete's scope to add such a function? git machete leaves returns a list of leaves?

Actually... there's already git machete list, but none of its subcommands returns exactly what's needed here. Lemme add an extra issue for that... I'd tentatively call it git machete list childless, for the sake of better consistency with the naming already in place

PawelLipski avatar Aug 08 '22 20:08 PawelLipski

Nice, that would be perfect!

LeeAlephium avatar Aug 08 '22 20:08 LeeAlephium

To be implemented & released soon, in v3.12.0 📦

PawelLipski avatar Aug 08 '22 20:08 PawelLipski

Oh! @LeeAlephium just in case, this is already available :)

PawelLipski avatar Aug 24 '22 21:08 PawelLipski

Yep, been following :wink: Thank you very much! You've done excellent work and I am very grateful. I apologize I've grown machete a tad even :smiling_face_with_tear:

LeeAlephium avatar Aug 24 '22 22:08 LeeAlephium

Haha thank you, no problem :)

PawelLipski avatar Aug 25 '22 08:08 PawelLipski