简体   繁体   English

如何在Git当前分支中获取最新的姓氏?

[英]How to get the latest head name in current branch in Git?

For example, in a git worktree of Linux Kernel. 例如,在Linux内核的git工作树中。

$ git checkout v2.6.6
$ git checkout v3.3

How to find the last head name or HASHID in current branch v3.3? 如何在当前分支v3.3中查找姓氏或姓氏? In the example above, it should get v2.6.6 or the HASHID for v2.6.6. 在上面的示例中,它应获取v2.6.6或v2.6.6的HASHID。

Thanks. 谢谢。

Every time you move the head git records it in the reflog . 每次移动头部git都会将其记录在reflog

$ git reflog

If you were to run this command after the commands in your question, the old commit hash would be on the second line down and will reference the tag you were moving to. 如果要在问题中的命令之后运行此命令,则旧的提交哈希将在第二行的下方,并将引用您要移至的标签。

For example 例如

ff06760 HEAD@{0}: checkout: moving from 9b49c22462f5dd73ff18eacff5983f141f98cb82 to v3.3
9b49c22 HEAD@{1}: checkout: moving from ff06760cd0db8cef49915e68886c66c09b1cade1 to v2.6.6

Expanding on Blake Taylor's answer, the last HEAD position is always HEAD@{1} , but this type of revision specification is so much more powerful than that: 扩展Blake Taylor的答案,最后一个HEAD位置始终是HEAD@{1} ,但是这种修订规范的功能远不止于此:

git checkout HEAD@{n} ;# checkout the nth prior position of HEAD
git checkout HEAD@{"1 hour ago"} ;# checkout HEAD an hour back
git checkout master@{"yesterday"} ;# checkout yesterday's master
git checkout master@{"1 week ago"} ;# checkout last week's
git checkout @{-1} ;# checkout the last branch checked out
git checkout @{-n} ;# checkout the nth last branch

and my personal favorite: 和我个人的最爱:

git checkout :/"<regex>" ;# checkout the youngest commit matching <regex>

... wait what? ......等什么? This syntax is awesome: 这个语法很棒:

git checkout :/"Case 959" ;# see the state when we fixed case 959
git checkout :/"ct/topic" ;# checkout the state when 'ct/topic' was merged
git checkout :/"^Hotfix" ;# checkout the most recent commit that started 'Hotfix'

Knowing these refspecs makes navigating your history easy. 了解这些refspec使浏览历史变得容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM