-
-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stack refactoring #3338
Comments
We could also use |
Decision needed on the behavior of the Consider this stack:
Currently, Option A:
This structure supports a scenario where I’m working on Option B:
This approach could be useful when splitting @ruudk you proposed this feature - which of these use cases did you have in mind? @stephenwade curious about your take on this as well. Thanks! |
Reading my original issue #3667 and thinking about my day to day, I often start hacking on a feature, and fix things along the way (scouts rule). These fixes are always done in separate commits, and are often independent of the feature. In that case I want to split the branch and move some of the commits to a parent (option B). Instead of creating a new |
That's a pretty brilliant idea, thanks for sharing! 🙏 I love that this allows us to implement this without introducing a new top-level command, as Git Town has a lot of top-level commands already. We could also add this |
Yeah depending on the use case doing a split on hack makes also sense. So let's add it to prepend append and hack. |
Regarding the naming, we're no longer "splitting" a branch mid-way; instead, we're selectively cherry-picking specific commits into the new branch. Let's find a better name for this workflow. Some ideas:
|
My script is called hack-pick. So maybe just --pick? |
In my opinion: For prepend/append, we shouldn't call it For hack, we shouldn't call it I suggest |
Another decision we have to make, which might also help with naming the CLI option: we now have two alternative approaches for selecting commits to move to the new branch. Approach A (the initial concept outlined earlier in this ticket): Split the branch at a specified commit, then move either all commits before or after this split point into the new branch. Approach B (suggested by @ruudk in #3667): Allow users to select individual commits to move into the new branch using checkboxes, enabling non-sequential commits to be moved. Approach A is much easier to implement and will cause fewer merge conflicts along the way. Approach B seems more flexible. When using approach A, it would make sense to name the CLI option There is also the option of implementing commit-moving as a standalone command, separate from creating new branches. This approach seems the most flexible, as it also allows moving commits between existing branches without creating any new branches. It comes at the cost of having to run two separate Git Town commands when extracting commits into a new branch. |
I think it would be nice to have both approaches. Sometimes I just want to split up what I have but keep them in a stack; sometimes I want to move a few commits out of this stack into an isolated branch. Also, after thinking about it some more, I think these should both be their own commands. Splitting a branch: When I realize that a PR is too big, I want to split it up. Having a separate command could also allow for a more flexible workflow, like picking multiple split points to create more than two branches or renaming both branches (e.g. start with branch Graphite split command documentation: https://graphite.dev/docs/squash-fold-split#split-a-branch-into-multiple-branches Moving commits: This should be its own command to allow moving commits between existing branches. I've definitely been in the situation of creating a commit for feature A on feature B's existing branch.
It would be nice to have one command to create branch + move commits, because that's probably the most common case for moving commits. Here are some convenience shortcut ideas:
|
@stephenwade I think this makes a lot of sense indeed 👍 |
Currently I manually turn each commit into a separate branch and PR. Git Town looks much better overall but lacks support for splitting a branch apart later in the process. I know this is open source but still I would like to ask if there are any plans on when this feature will be implemented (a few weeks, months, years away)? |
Thanks, everyone, for your thoughtful input—this discussion has been incredibly insightful! Here’s a quick recap of where we stand based on the feedback so far: Splitting a branch: not practical; extracting commits: promisingThe idea of splitting a branch initially sounded intriguing but seems to address only a narrow set of use cases mentioned in this thread. Given its limited applicability and the additional complexity it would introduce, we’re shelving this concept for now. Conversely, enabling users to view all commits in a branch and select specific ones (via checkboxes) to move to another branch—either new or existing—addresses all of the discussed scenarios. Extracting commits into a new branch: highly requestedA key takeaway is the widespread need for extracting specific commits from an existing branch into a new one. The most natural fit for Git Town would be to introduce a Moving commits to an existing branch: fills a gapA dedicated Let me know if I’ve missed anything or if there’s more we should consider! |
Feedback requested: It would be great if somebody who is already manually moving commits between branches shares how they do it. What’s the sequence of Git commands to move a single commit to another branch and remove it from its original branch? ContextConsider my workspace contains branches
I run
Desired end state
possible approachesChatGPT suggests the following Git commands: SHA=<SHA of commit-2>
git checkout branch-2
git cherry-pick $SHA
git checkout branch-1
git rebase --onto "$SHA^" "$SHA" Open questions
|
I use cherry-pick (see #3667 (comment)). As you can see, if you have the SHA's of the commits, you don't need to checkout to the old branch anymore. |
Move down:
Move up:
|
I use cherry-pick to move commits, then interactive rebase to remove the commits from the previous branch.
This works if you are moving only one commit.
It would require multiple rebases if you are moving multiple commits, and I think that might mean multiple resolutions of the same conflict.
I think a better approach would be to cherry-pick any commits after the first moved one. This would replicate a single interactive rebase, and only require resolving any conflicts once.
Yes, any time a rebase happens any descendant branches need to be rebased so they have the new branch tip in their ancestry. |
motivation
Not sure if this is something people do a lot or even should should do a lot. But if they do it, they should do it using Git Town. Because Git Town
how it works
merge
sync-strategy need tocompress
their branch first--onto
option for rebase will do the heavy lifting hereBranch commands
Some of these commands could be top-level commands, but they aren't used often enough to justify being a top-level command.
git town set-parent
- moves the current branch to a different position in the lineageup
,down
,first
, andlast
commands do, and more (moving to a different stack)UI
The UI is similar to
git town switch
, but moves the highlighted branch up and down.git town merge
- merge two consecutive branches in a stackexample
Given this stack:And I am on
branch-2
When I run
git town merge
Then I have this stack:
And
branch-1
contains the changes ofbranch-1
andbranch-2
.git town hoist
- detach the current branch from its stack (make it an independent top-level branch)example
Given this stack:
And I am on
branch-2
When I run
git town detach
Then I have this stack:
git town hack --beam
- extract a commit into a new branchexample
Given this stackAnd
branch-1
contains multiple commitsAnd I am on the
branch-1
branchWhen I run
git town hack --move branch-2
Then it asks me to select the commits to go into the new branch
And I have this stack:
UI
git town append --beam
- creates a child branch and beams a commit into itgit town prepend --beam
- creates a new parent branch and beams a commit into itUI
The text was updated successfully, but these errors were encountered: