Skip to content
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

branch create --below: Allow modifications to files in current branch #149

Open
abhinav opened this issue Jun 3, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@abhinav
Copy link
Owner

abhinav commented Jun 3, 2024

branch create --below detaches to the commit right before the current branch to insert the new commit at.
Git will refuse this operation if there are uncommitted changes to files that are also modified in the commits we're going under.
E.g., if we had:

git add foo.txt
gs branch create foo

$EDITOR foo.txt
git add foo.txt
git branch create --below bar

This will fail because the uncommitted changes to foo.txt will be lost from the current context.

This may be solvable with the --merge flag of git-checkout:

       -m, --merge
           When switching branches, if you have local modifications to one or more files that are
           different between the current branch and the branch to which you are switching, the command
           refuses to switch branches in order to preserve your modifications in context. However, with
           this option, a three-way merge between the current branch, your working tree contents, and
           the new branch is done, and you will be on the new branch.

           When a merge conflict happens, the index entries for conflicting paths are left unmerged, and
           you need to resolve the conflicts and mark the resolved paths with git add (or git rm if the
           merge should result in deletion of the path).

           When checking out paths from the index, this option lets you recreate the conflicted merge in
           the specified paths. This option cannot be used when checking out paths from a tree-ish.

           When switching branches with --merge, staged changes may be lost.

We would need a way to handle conflicts in that process, though; perhaps just reject any changes that would conflict.

@abhinav abhinav added the enhancement New feature or request label Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant