获取以前的分支名称 [英] Get previous branch name
问题描述
我真的很喜欢git checkout -
移到我以前的分支.
I really like git checkout -
to move to my previous branch.
但是有时候我只需要知道我以前的分支名称是什么.我该怎么问Git?
But sometimes I only need to know what my previous branch name is. How could I ask Git that?
例如,如果git checkout -
移至分支"prev",我希望该命令仅获取"prev".
For example, if git checkout -
moves to branch "prev", I want the command to get just "prev".
推荐答案
git checkout -
是git checkout @{-1}
的简写(请参阅
git checkout -
is shorthand for git checkout @{-1}
(see here):
您可以使用
@{-N}
语法引用第N个最后一个分支/提交 使用"git checkout"操作签出.您也可以指定-
是@{-1}
的同义词.
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
提交或分支相关问题:
You can pass this same reference to rev-parse
to get the commit or branch in question:
$ 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
这篇关于获取以前的分支名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!