Git commit --amend别名引发rebase异常,请求排查原因
am Isn't Working & Causes a "Stuck" State Let's break down exactly what's happening here—this is a classic case of conflicting with Git's built-in commands, which is easy to miss when setting aliases.
The Root Cause
You created an alias am = commit --amend --no-edit, but Git has a native git am command that takes priority over user-defined aliases. This built-in command is designed to apply patch files (typically from email-based workflows), and when you run it without any arguments, it waits for input from your terminal's standard input (stdin)—that's why it's "stuck" waiting for you to paste a patch, not because it's triggering a rebase (though the hanging behavior might feel similar to rebase prompts).
Why Your Alias Isn't Being Triggered
Git looks for commands in this strict order:
- Built-in core commands (like
am,commit,push) - User-defined aliases
- External scripts named
git-*
Since am is a built-in command, Git ignores your alias entirely when you type git am—it's running the native patch-applying tool, not your commit --amend shortcut.
How to Fix It
You have two straightforward solutions:
Option 1: Rename Your Alias (Recommended)
Pick a name that doesn't clash with Git's built-in commands. For example:
git config --global alias.gam "commit --amend --no-edit"
Now you can run git gam to trigger your amend shortcut, and git am will still work for its original patch-applying purpose.
Option 2: Override the Built-in Command (Use With Caution)
If you really want to keep am as your alias, you can force Git to run your command by wrapping it in a shell command (using !):
git config --global alias.am "!git commit --amend --no-edit"
This tells Git to execute the alias as a shell command instead of trying to match a built-in command. Note: This will completely overwrite the native git am command—you won't be able to run the original patch tool with git am anymore unless you use a workaround like \git am or call the Git binary directly.
Verifying the Fix
After updating your alias, run git config --global -e to confirm the change, then test it in your test repo:
- If you used Option 1: Run
git gam—you'll get the expectedfatal: You have nothing to amend.error when there's no commit to modify. - If you used Option 2: Run
git am—you'll get the same error instead of getting stuck waiting for input.
内容的提问来源于stack exchange,提问作者Alex Telon

