One my colleagues accidentally ran git merge -
and it seemed to merge the branch they were last on. Fascinating. git describe -
errors out fatal: Not a valid object name -
. git symbolic-ref --short -
also errors out with fatal: ref - is not a symbolic ref
.
It's obviously(?) impossible to search for this. Where is this documented, is this merge specific, if not where else could it be used?
Edit: our principal sw engineer pointed out https://git-scm.com/docs/git-checkout You may also specify - which is synonymous to @{-1}
so I guess the same happens to git merge
but a) it's not documented under git merge
b) git describe
or git log
doesn't work with -
while both work with @{-1}
c) it's still not clear where else could it be used especially if it's undocumented.
CodePudding user response:
The dash syntax to represent @{-1}
is implemented in some commands and not others, and its design comes from cd
, which typically supports a similar feature (switching to the last directory).
It's known upstream that it's not implemented in all commands, and the threshold for implementing it is roughly, "Is it useful in this case to refer to the immediately previous branch in this context?" Clearly it's useful in checkout, switch, and restore, but nobody thought it was useful in log, so it wasn't implemented. If you can make a compelling argument for implementing it, patches would be welcome. The Git list has received patches for this in the past.
The reason it doesn't work everywhere is because it's implemented on a command-by-command basis instead of in the revision parsing machinery, like @{-1}
is. Things implemented in the revision parsing machinery (documented in the gitrevisions(7)
manual page) will be available everywhere.