不需要一直检出master
,或在纸上写下大量的SHA-1。在任何阶段,您都可以运行
git log --oneline --decorate --graph master
为了方便起见,您可能希望定义以下别名,因为许多Git用户都这样做:
git config alias.lg "log --oneline --decorate --graph"
那么上述命令就变得非常简单了。
git lg master
这将输出您的
master
分支的整个祖先日志(虽然以简洁的形式),无论您在提交图中的哪个位置。
这是一个很好的方法,可以帮助您确定要检查或检视哪个提交,通过相应的短 SHA-1 哈希值。请注意,使用
--decorate
标志会显示您在哪里(
HEAD
)。
示例
以下是我浏览自己一个 Git 代码库的示例:
$ git branch
* master
$ git tag
v0.1
v0.2
v0.3
$ git checkout v0.3
Note: checking out 'v0.3'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at cfc71e4... mention compatibility with subset of Octave syntax
$ git log --oneline --decorate --graph master
* 73ec762 (origin/master, origin/HEAD, master) improve brace style
* ffc8d67 remove superfluous word; delete trailing whitespace
* 3f8b8db remove obsolete comment about mcode
* f9f9fd0 remove .DS_Store file that was accidentally added
* cc855ab clarify description of mlonlyheader option
* 7553ccf change contact email
* 4d860e9 correct remarks on shell-escape and backtick
* 9a2ef02 corrected typo in Tips & tricks
* f0badb5 minor improvements in documentation
* cfc71e4 (HEAD, tag: v0.3) mention compatibility with subset of Octave syntax
* 7db2c88 Preventive bugfix: replace \toks@ by \toks@mlpr
* 01fdc43 delete OS-specific files from .gitignore
...
git checkout master~82
...git checkout master~77
等等是 Git 命令,用于切换到在 Git 中标记为 "master" 的分支中的某个先前提交的版本。 ~ 后面的数字表示要向后回滚的提交次数。 - Sascha Wolf