Reputation: 1202
I'm wondering why my git alias got stuck and how it caused a rebase.
Steps to reproduce:
git config --global alias.am "commit --amend"
I can see that the alias is added with:
git config --global -e
[alias]
am = commit --amend --no-edit
Create new test repo:
> git init
> git am
Ctrl + c, Ctrl + c
Nothing happens so I have to close it manually. The expected result would be fatal: You have nothing to amend.
in this case since there are no commits. But what happens is that git is now in rebase mode: (master|AM/REBASE)
When running in a repo with a commit, the expected result is to open my default git editor so I can edit the commit message but the same unexpected behaviour explained above happens.
The question
How come my git am alias gets stuck as it does, and how does it put me in a rebase situation?
What I have tried
I guess that my git alias is faulty in some way and that it causes it to start the git commit --amend
but in a way so its unable to start the editor. And since a git commit --amend probably does a rebase in the background to do its thing it is left in that state when I force it to abort?
However, I have tried to add --no-edit to no avail so it seems not to be an editor error..
This issue caused me to accidentally do a git rebase --abort
and lose some local non-staged changes.
System
I'm on Windows 10 using Git Bash.
I have tested using both emacs and notepad as my default git editors, both with the same result.
Upvotes: 1
Views: 2735
Reputation: 1202
The issue was that git am
already is a command.
In general when dealing with git alias, note that.
Git gives no warning when you try to overwrite an already existing keyword.
Git still saves the alias in the config file.
When writing a new git alias remember to test if the alias you intend to use already exists and hope that it's not added as a keyword in the future.
Upvotes: 3
Reputation: 30888
According to the document on alias.* in git-config
,
To avoid confusion and troubles with script usage, aliases that hide existing Git commands are ignored.
am
is an existing Git command, so alias.am
is ignored. git am
is waiting for some input but nothing is received, neither from stdin or a patch file. So it looks stuck.
When you press Ctrl+C to exit, the process of git am
is interrupted as if it encounters a conflict. A temporary folder rebase-apply
is created under .git
. With this folder existing, Git knows it's in the status (master|AM/REBASE)
. You could either remove .git/rebase-apply
or run git am --abort
to get rid of it.
Upvotes: 1