git-machete
git-machete copied to clipboard
Question: how to conveniently merge all HEADs?
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!
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?
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!
Huh I've got a déjà vu... a similar thing has been suggested by my colleague @kgadek recently.
Our observations/conclusions were that:
- Currently there's no support for anything similar in git-machete CLI nor in the IntelliJ plugin.
- Syntax in .git/machete that would provide support for this feature, for a branch layout like:
could look like that:
(with ..selected so that it cannot start a valid branch name. - 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
octopusmerge strategy, used for merging 3+ branches (git merge A B [C [D ...]]) doesn't resolve modifications to the same file as smoothly as the defaultortstrategy does. - 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
ortstrategy). Or your variation, with--no-commit(but that's still, 2 branches merged withort). I guess Konrad could share his own version of the script if needed ;) - 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 😅
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?
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
Nice, that would be perfect!
To be implemented & released soon, in v3.12.0 📦
Oh! @LeeAlephium just in case, this is already available :)
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:
Haha thank you, no problem :)