获取以前的分支名称

Get previous branch name

我很喜欢git checkout -搬到我以前的分店。

但有时我只需要知道我以前的分支名称是什么。我怎么能问 Git 呢?

例如,如果 git checkout - 移动到分支 "prev",我希望命令只得到 "prev"。

git checkout - 对于 git checkout @{-1} 是 shorthand(参见 here):

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}.

您可以将相同的引用传递给 rev-parse 以获取有问题的提交或分支:

$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
$ git checkout not-master
Switched to branch 'not-master'
Your branch is up to date with 'origin/not-master'.
$ git rev-parse --symbolic-full-name @{-1}
refs/heads/master