如何从 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:42:32  来源:igfitidea点击:

How can I get a Git log from HEAD?

git

提问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不会影响您的工作树。所以,它是安全的。

  1. git fetch origin

    Here originis your remote repo. This command fetches the latest data from the remote repo.

  2. git log origin\master

    Here origin\masterimplies masterbranch in the remote repo origin. This command shows log from origin\master.

  1. git fetch origin

    origin是您的远程仓库。此命令从远程存储库中获取最新数据。

  2. 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 --graphgraph将每个提交与 ASCII 艺术线条链接以查看它们的关系。如果我想同时查看更多信息,--oneline也很有帮助。