I know that the command git checkout - checks you out to the previous active branch or detached HEAD.
What I would like to know is if the command git merge - merges the previous active branch or detached HEAD to my currently checked out branch.
I know that the command git checkout - checks you out to the previous active branch or detached HEAD.
What I would like to know is if the command git merge - merges the previous active branch or detached HEAD to my currently checked out branch.
Your assumption is correct and git merge - merges the branch/commit checked out before the current one into your currently checked out branch.
The release notes for Git 1.7.6 explicitly state this:
git mergelearned-as a short-hand for the previous branch, just like the waygit checkout -works.
In commands that allow this, - is a shorthand for @{-1} which is specified in gitrevisions:
@{-<n>}, e.g. @{-1}
The construct@{-<n>}means the <n>th branch/commit checked out before the current one.
By looking through the release notes and the source code, I was able to identify the following commands that support a lone - as a short hand for @{-1}:
The documentation for git-checkout describes how you can describe the branch you want using the @{-N} syntax:
You can use the @{-N} syntax to refer to the N-th last branch/commit checked out using "git checkout" operation. You may also specify - which is synonymous to @{-1}.
So far I haven't found any other documentation that says - is synonymous with @{-1}, but this notation is documented in git-revisions which means that it's more general than just for use with git checkout. It seems reasonable to think you can use it whereever a branch or commit is required.
I habitually use both git checkout - and git merge -. They are very useful, and I've never had a problem with either of them. So to answer your question directly, yes, git merge interprets - just like git checkout. That said, it's a shame the documentation is so arcane.
other answers give correct pointers to the documentation, here is how it is currently (version 2.32) implemented :
git scans the reflog for the latest line looking like :
checkout: moving from xxx to yyy
and uses xxx as the target reference.
@{-2} searches for the second latest line, @{-3} for the third latest line, etc ...
You can try it on a test repo : the reflog for HEAD is simply a file stored at .git/logs/HEAD.
Note that, in that file, lines are written in chronological order : the oldest line is at the top, the most recent at the bottom. This is the reverse of what you see when you run git reflog, where the oldest line is at the bottom and the most recent at the top.
If you edit it (warning : editing the reflog by hand can break things, do this on a test repo, not on your main working repository), and change the the messages for the last checkout: ... line, you will see that commands such as git checkout - or git rev-parse --abbrev-ref @{-XX} change behavior accordingly.