我怎么知道我以前在哪个分支上?更确切地说,git checkout -
将转到哪个分支?
如果上一个分支不是我要签出的分支,我还想知道以前还有哪些分支。
换句话说,如何看待“分支”的历史?不是当前分支的提交历史,而是我签出的分支的历史。
我在搜索中发现的所有内容都是关于提交历史的。
答案 0 :(得分:3)
git show --decorate -s @{-1}
原始答案:
reflog似乎确实保留了HEAD
的移动位置的历史记录,并且看起来可以由HEAD@{#}
变量访问。
但是,这还包括重置,重新设置基数,执行点和提交。我认为这是因为所有这些命令都会移动HEAD
。
104f63b (HEAD -> master, master.bak) HEAD@{0}: checkout: moving from b2 to master
e97431a (b2) HEAD@{1}: checkout: moving from b1 to b2
588aa76 (b1) HEAD@{2}: cherry-pick: C6
befdf09 HEAD@{3}: reset: moving to befdf09b
80cf3dd HEAD@{4}: checkout: moving from master to b1
104f63b (HEAD -> master, master.bak) HEAD@{5}: checkout: moving from b2 to master
e97431a (b2) HEAD@{6}: cherry-pick: C7
befdf09 HEAD@{7}: reset: moving to befdf09b
4dd1828 HEAD@{8}: checkout: moving from master to b2
104f63b (HEAD -> master, master.bak) HEAD@{9}: commit: C5
be1bfdb HEAD@{10}: commit: C4
07743f7 HEAD@{11}: commit: C3
befdf09 HEAD@{12}: checkout: moving from b1 to master
80cf3dd HEAD@{13}: commit: C6
4dd1828 HEAD@{14}: checkout: moving from b2 to b1
4dd1828 HEAD@{15}: commit: C7
befdf09 HEAD@{16}: checkout: moving from master to b2
befdf09 HEAD@{17}: commit: C2
464acc2 HEAD@{18}: commit (initial): C1
如果检查引用日志过多there is a program to help with that。
答案 1 :(得分:-2)
只需键入history
。它将为您提供您在Shell中键入的所有先前命令。