You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes (especially when doing modifications in a submodule, inside a super-repo) I end up (accidentally) committing something at a "detached HEAD".
(It's also easy to cause a detached HEAD by using the Checkout Commit context-command in the History graph, and then forget to checkout a branch before committing.)
Having done such a "detached" commit, there is a risk of losing the commit (and being forced to rescue it from reflog) if then checking out a branch.
Most likely, at least in the submodule case, HEAD was already coinciding with a branch-tip before my commit. What I'd like to do in this situation is simply to "move" that branch-pointer forward to point at my new commit. (A more cumbersome alternative would be to: create a temporary branch/tag to point at the new commit, checkout the original branch and reset it to the new commit, then delete the temporary branch/tag.)
However, there is no command in SourceGit to (forcefully) "move" a specified local branch-pointer so it points at another commit. There is the 'Reset <branch> to Here' command, but that only works for a checked-out branch. On the Git command-line, on the other hand, it's easy to accomplish what I describe (using the --force flag) :
git branch -f <branch> HEAD
Suggestion: add a context-command for Local Branches, similar to the 'Fast-forward to <remote tracking branch>' command, allowing us to "move" (or "fast-forward") any local branch so it points at the current (detached) HEAD.
The Git command for this would be git branch -f <branch> HEAD, but the context action could be implemented in one of two variants (depending on how much "sanity-checking" we want to apply) :
Fast-forward to HEAD
Needs additional check (git merge-base --is-ancestor <branch> HEAD; echo $?) to determine if <branch> can be fast-forwarded.
Move to HEAD
Needs no additional checks - is more general (and thus useful in more cases) but also a bit more "risky" (since we could lose track of the previous branch-tip, if the branch is "moved" to point at an earlier or unrelated/unreachable commit). This variant may need user confirmation before actually performing the action.
This command could be hidden or disabled (grayed-out) when HEAD is NOT detached. Alternatively, it could be always active, allowing us to re-point any local branch to the current commit (regardless of HEAD detached status).
NOTE: The 1st (safer) variant of this context-command could be incorporated into the 2nd (more general) variant, by implementing the ancestor-check as an option CheckBox 'Only allow fast-forward' (or similar) in a option/confirmation dialog for the command.
The text was updated successfully, but these errors were encountered:
However, there is no command in SourceGit to (forcefully) "move" a specified local branch-pointer so it points at another commit. There is the 'Reset to Here' command, but that only works for a checked-out branch. On the Git command-line, on the other hand, it's easy to accomplish what I describe (using the --force flag) :
If you checkout to your branch, reset can be used.
Sometimes (especially when doing modifications in a submodule, inside a super-repo) I end up (accidentally) committing something at a "detached HEAD".
(It's also easy to cause a detached HEAD by using the
Checkout Commit
context-command in the History graph, and then forget to checkout a branch before committing.)Having done such a "detached" commit, there is a risk of losing the commit (and being forced to rescue it from reflog) if then checking out a branch.
Most likely, at least in the submodule case, HEAD was already coinciding with a branch-tip before my commit. What I'd like to do in this situation is simply to "move" that branch-pointer forward to point at my new commit. (A more cumbersome alternative would be to: create a temporary branch/tag to point at the new commit, checkout the original branch and reset it to the new commit, then delete the temporary branch/tag.)
However, there is no command in SourceGit to (forcefully) "move" a specified local branch-pointer so it points at another commit. There is the '
Reset <branch> to Here
' command, but that only works for a checked-out branch. On the Git command-line, on the other hand, it's easy to accomplish what I describe (using the--force
flag) :git branch -f <branch> HEAD
Suggestion: add a context-command for Local Branches, similar to the '
Fast-forward to <remote tracking branch>
' command, allowing us to "move" (or "fast-forward") any local branch so it points at the current (detached) HEAD.The Git command for this would be
git branch -f <branch> HEAD
, but the context action could be implemented in one of two variants (depending on how much "sanity-checking" we want to apply) :Fast-forward to HEAD
git merge-base --is-ancestor <branch> HEAD; echo $?
) to determine if<branch>
can be fast-forwarded.Move to HEAD
This command could be hidden or disabled (grayed-out) when HEAD is NOT detached. Alternatively, it could be always active, allowing us to re-point any local branch to the current commit (regardless of HEAD detached status).
NOTE: The 1st (safer) variant of this context-command could be incorporated into the 2nd (more general) variant, by implementing the ancestor-check as an option CheckBox '
Only allow fast-forward
' (or similar) in a option/confirmation dialog for the command.The text was updated successfully, but these errors were encountered: