Skip to content

Git: show commit amend option on detached HEAD#305034

Open
Sathvik-Chowdary-Veerapaneni wants to merge 1 commit intomicrosoft:mainfrom
Sathvik-Chowdary-Veerapaneni:commit-amend-detached-head-247936
Open

Git: show commit amend option on detached HEAD#305034
Sathvik-Chowdary-Veerapaneni wants to merge 1 commit intomicrosoft:mainfrom
Sathvik-Chowdary-Veerapaneni:commit-amend-detached-head-247936

Conversation

@Sathvik-Chowdary-Veerapaneni

Fixes #247936

Problem

When working on a detached HEAD (e.g., git checkout HEAD~1), the commit button dropdown in the Source Control view shows no secondary commands. This means the "Commit (Amend)" option is not available, even though amending commits is a common and valid workflow on detached HEADs.

Root Cause

In actionButton.ts, getCommitActionButtonSecondaryCommands() returns an empty array when HEAD is a tag or has no branch name (detached HEAD). This was likely done to avoid showing post-commit commands like "Push" and "Sync" that don't apply without a tracking branch, but it also incorrectly hid the basic "Commit" and "Commit (Amend)" options.

Fix

Instead of returning an empty array for detached HEAD, the method now returns a command group containing the "Commit" and "Commit (Amend)" commands. Post-commit commands (push/sync from providers) are still excluded since they require a tracking branch.

The fix matches the existing patterns in getCommitActionButtonPrimaryCommand() (which already correctly shows a plain "Commit" command for detached HEAD) and postCommitCommands.ts getCommitCommands() (which already defines both commit and amend commands).

Test Plan

  • Checkout a detached HEAD (git checkout HEAD~1)
  • Open Source Control view
  • Click the dropdown on the commit button
  • Verify "Commit" and "Commit (Amend)" options are now shown
  • Verify push/sync options are NOT shown (correct, since there's no tracking branch)
  • Switch back to a branch and verify all options (commit, amend, push, sync) still appear normally

When working on a detached HEAD, the commit button dropdown was
returning no secondary commands, hiding the amend option. This
change shows commit and commit amend commands for detached HEAD
while still excluding post-commit commands (push/sync) that don't
apply without a tracking branch.

Fixes microsoft#247936
@vs-code-engineering
Copy link
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@lszomoru

Matched files:

  • extensions/git/src/actionButton.ts

@vs-code-engineering vs-code-engineering bot added this to the 1.114.0 milestone Mar 26, 2026
@Sathvik-Chowdary-Veerapaneni
Copy link
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No option for commit --amend if working with detached HEAD

2 participants