git log 向我展示了什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11584220/
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:15:17  来源:igfitidea点击:

What does git log show me?

git

提问by firebush

I'm missing something. I used to use Mercurial and would look at the revision history of the repo with hg log. Simple: allchangesets ever made in the repo are shown.

我错过了一些东西。我曾经使用 Mercurial,并会使用hg log. 简单:显示在 repo 中所做的所有更改集。

Now I'm using git. I'm pretty excited about learning the new tool, but I'm confused by what I'm seeing with git log. I've done some changes and made some commits. Another person has created a revision and committed as well. I pulled from his repository. I do a git logand his changeset (maybe it's called "commit" in git) isn't in the list. If I explicitly list his hash number (ie, git log <hash>), it shows up at the top. So it isin my repo, but I don't understand how git is deciding to show me what it does when I call git log.

现在我正在使用 git。我对学习新工具感到非常兴奋,但对我所看到的git log. 我做了一些更改并进行了一些提交。另一个人已经创建了一个修订版并提交了。我从他的存储库中提取。我做了一个git log,他的变更集(可能在 git 中称为“提交”)不在列表中。如果我明确列出他的哈希值(即git log <hash>),它会显示在顶部。因此,它在我的回购,但我不明白Git是如何决定告诉我什么,当我把它做git log

I look at the git help log, but it says in the description that it "shows the commit logs." From my perspective, that's incorrect. Or perhaps incomplete because in reality it shows some subset of them. But I don't know what subset nor how it determines what to show.

我查看了git help log,但它在描述中说它“显示提交日志”。从我的角度来看,这是不正确的。或者可能是不完整的,因为实际上它显示了其中的一些子集。但我不知道是什么子集,也不知道它如何确定要显示的内容。

Can someone explain git logto me?

有人可以git log向我解释一下吗?

Update

更新

btw: One of the first things I had tried was --all, and I see now that many people suggest it. But that doesn't show it either:

顺便说一句:我尝试过的第一件事是 --all,现在我看到很多人都建议这样做。但这也没有显示出来:

$ git log | grep fb2a17c5fb08498e7f2ab364931fddc379be106f 
$ git log --all | grep fb2a17c5fb08498e7f2ab364931fddc379be106f 
$ git log fb2a17c5fb08498e7f2ab364931fddc379be106f  | grep fb2a17c5fb08498e7f2ab364931fddc379be106f 
commit fb2a17c5fb08498e7f2ab364931fddc379be106f

回答by Adam Dymitruk

There is an implied argument to git logwhen you don't specify a reference or set of references. It is the current head. So

git log当您不指定引用或引用集时,有一个隐含的参数。它是当前的头。所以

git log

expands to

扩展到

git log HEAD

which means show me all the commits reachable from the current HEAD (where your next commit will attach).

这意味着向我展示从当前 HEAD 可访问的所有提交(您的下一个提交将附加到该提交)。

In order to see your colleague's work, you can

为了查看同事的工作,您可以

git log origin/master

assuming you are both working on master and you fetched already.

假设你们都在 master 上工作并且你已经获取了。

In git, fetch means get the commits from the remote but don't update any of my local branches. git pullwill do fetch and then merge your branch with what it fetched. It is a good idea to fetch, inspect what was done and then merge or rebase or even reject what was done with a force push - depends on the situation and your workflow.

在 git 中,fetch 意味着从远程获取提交但不更新我的任何本地分支git pull将执行获取,然后将您的分支与其获取的内容合并。获取、检查已完成的内容,然后合并或变基甚至拒绝强制推送所做的内容是一个好主意 - 取决于情况和您的工作流程。

typically, to see what was done on the remote after a fetch you can

通常,要查看获取后在遥控器上执行的操作,您可以

git log ..origin/master

this really expands to

这真的扩展到

git log HEAD..origin/master

the ..operator is short hand for combining "exclude reachable commits from this reference" and "include reachable commits from this reference". So it could also be written like this:

..操作者是短手“从这个参考文件中排除可达提交”和组合“包括从该基准到达提交”。所以也可以这样写:

git log ^HEAD origin/master

the ^at the beginning of a reference means exclude the commits reachable from here. In this case it means what you have reachable from where you are. The result will be a list of the commits on this branch just fetched from the server.

^在基准工具开始排除从这里提交到达。在这种情况下,它意味着您可以从您所在的位置到达。结果将是刚刚从服务器获取的此分支上的提交列表。

Instead of listing all the branches and remote branches as arguments to git log, you can just use the --allparameter:

git log您可以只使用--all参数,而不是将所有分支和远程分支列为的参数:

git log --all

which will show all commits reachable from all branches (local and remote tracking) and tags.

这将显示所有分支(本地和远程跟踪)和标签可访问的所有提交。

git logis a very powerful command due to how it allows you to do set based reductions of what commits you want to see. ..is a good syntax to know. There is also ...which says to include commits from both the branches specified down to their common ancestor.

git log是一个非常强大的命令,因为它允许您对想要查看的提交进行基于集合的减少。..是一个很好的语法。还有一种...说法是包括从指定的两个分支到其共同祖先的提交。

This walking of history is what makes git so powerful and able to support so many interesting workflows.

正是这段历史让 git 如此强大并能够支持如此多有趣的工作流程。

UPDATE:

更新:

When git encounters commits that are identical in terms of what is contained in the tree stored there with it's parent, it will not list the commit when it walks a merge.

当 git 遇到与其父级存储在那里的树中包含的内容相同的提交时,它不会在执行合并时列出提交。

git log --all --sparse

will not exclude those commits.

不会排除这些提交。

see the history simplification section of http://linux.die.net/man/1/git-log

参见http://linux.die.net/man/1/git-log的历史简化部分

It could also mean that you reset a branch or your friend did and fetching again has lost that reference. When you do git log with the sha1, what is the output if you add --decorate to it? Also try git log --walk-reflogs.

这也可能意味着您重置了一个分支,或者您的朋友做了并且再次获取已经丢失了该引用。当您使用 sha1 执行 git log 时,如果向其添加 --decorate 输出是什么?也试试git log --walk-reflogs

回答by twalberg

git logwithout any further explicit arguments shows you the history of the commit you currently have checked out. If you want to look at other branches or commits, you have to tell git logwhat you want to look at.

git log没有任何进一步的明确参数向您显示您当前已签出的提交的历史记录。如果要查看其他分支或提交,则必须说明git log要查看的内容。

git log --all

should show all revisions on all branches.

应该显示所有分支上的所有修订。

There are quite a few good tutorials out there for easy googling.

有很多很好的教程可以轻松使用谷歌搜索。

回答by razeh

You're right --- by default git log only shows you a subset of commits. By default git log only shows commits visible from the tip of your current branch. Your friend's commit isn't in your current branch yet, so it does not show up in git log.

你是对的 --- 默认情况下 git log 只显示提交的子集。默认情况下 git log 仅显示从当前分支的尖端可见的提交。你朋友的提交还没有出现在你当前的分支中,所以它不会出现在 git log 中。