如何从 HEAD 获取 Git 日志?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13226281/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I get a Git log from HEAD?
提问by Sungguk Lim
I am originally an SVN user.
我原本是一个 SVN 用户。
In Git, git logshows only the log from the current commit.
在 Git 中,git log仅显示当前提交的日志。
How can I get the log from HEAD?
我怎样才能得到日志HEAD?
回答by Karthik Bose
To get log from server-side HEAD, you need to fetch changes from the server first. Unlike pull, fetchis not going to affect your working tree. So, it's safe.
要从服务器端 HEAD 获取日志,您需要先从服务器获取更改。与pull,fetch不会影响您的工作树。所以,它是安全的。
git fetch originHere
originis your remote repo. This command fetches the latest data from the remote repo.git log origin\masterHere
origin\masterimpliesmasterbranch in the remote repoorigin. This command shows log fromorigin\master.
git fetch origin这
origin是您的远程仓库。此命令从远程存储库中获取最新数据。git log origin\master这里
origin\master暗示master远程 repo 中的分支origin。此命令显示来自origin\master.
Other useful git logoptions:
其他有用的git log选项:
i) git log HEAD..origin\master
一世) git log HEAD..origin\master
Show the commits that are in the "origin/master" branch but not yet in the "HEAD".
显示在“origin/master”分支中但尚未在“HEAD”中的提交。
ii) git log -p HEAD..origin\master
ii) git log -p HEAD..origin\master
Show the commits as a patch.
将提交显示为补丁。
iii) git log -5
三) git log -5
Shows the latest 5 commits.
显示最近的 5 次提交。
回答by linquize
As you only need one revision, run
由于您只需要一个修订版,请运行
git log -n 1
git log -n 1
or
或者
git log -n 1 HEAD
git log -n 1 HEAD
回答by Adam Dymitruk
git log
implies
暗示
git log HEAD
HEADis implied in other commands as well when issuing no reference. HEADmeans "current commit" - regardless of what branch you are on - or even if you are not on any branch. If you want to see all references, you can do
HEAD当不发出引用时,也隐含在其他命令中。HEAD表示“当前提交”——不管你在哪个分支——或者即使你不在任何分支上。如果您想查看所有参考文献,您可以这样做
git log --all --decorate
allwill show you all references (tips of any branches) and their ancestors. decoratewill mark the output commits with any references that point to them. You can make that the default behaviour for the current user with git config --global log.decorate true.
all将向您显示所有引用(任何分支的提示)及其祖先。decorate将使用指向它们的任何引用标记输出提交。您可以使用 将其设为当前用户的默认行为git config --global log.decorate true。
With the above configuration I usually do git log --all --graph. graphlinks each commit with ASCII art lines to see their relationships. If I want to see more information at the same time, --onelineis also helpful.
有了上面的配置我通常会这样做git log --all --graph。graph将每个提交与 ASCII 艺术线条链接以查看它们的关系。如果我想同时查看更多信息,--oneline也很有帮助。

