git log显示我什么? [英] What does git log show me?

查看:229
本文介绍了git log显示我什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我错过了一些东西。我曾经使用Mercurial,并会使用 hg log 来查看repo的修订历史记录。简单:显示回购站中所有更改集。



现在我正在使用git。我对学习新工具感到非常兴奋,但是我对 git log 看到的结果感到困惑。我做了一些改变并做了一些提交。另一个人已经创建了一个修订并承诺。我从他的存储库中取出。我做了一个 git log 和他的变更集(也许它在git中叫做commit)不在列表中。如果我明确列出他的散列号(即 git log< hash> ),它会显示在顶部。因此,在我的回购库中,,但我不明白git是如何决定告诉我它在调用 git log 时的功能。



我看看 git help log ,但它在描述中说它显示提交日志。从我的角度来看,这是不正确的。或者可能不完整,因为实际上它显示了它们的一部分。但我不知道哪个子集,也不知道它是如何显示的。



有人可以解释 git log 来我是谁?



更新



btw:我尝试过的第一件事就是 - 现在看到很多人提出这个建议。但是这并没有显示出来:

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


解决方案

当你没有指定一个引用或一组引用时,隐含的参数为 git log 。这是目前的头。所以

  git log 

扩展为

  git log HEAD 

这意味着向我显示所有可从当前HEAD获得的提交(您的下一个提交将附加到此处)。



为了看到你的同事的工作,你可以

  git log origin / master 

假设您已经在master上工作了,并且已经提取了。

在git中,获取意味着从远程获取提交,但不更新任何本地分支 git pull 会执行提取操作,然后将您的分支与其提取的内容合并。这是一个好主意,可以检查,检查完成了什么,然后合并或重新绑定,甚至拒绝使用强制推送完成的工作 - 取决于情况和工作流程。



通常情况下,要查看获取后遥控器上完成的操作,您可以

  git log ..origin / master 

这真的会扩展到

  git log HEAD..origin / master 

.. 操作符用于组合从此引用中排除可达到的提交和包含来自此引用的可达到提交。所以它也可以这样写:

  git log ^ HEAD origin / master 

在引用开头的 ^ 意味着排除可从此处访问的提交。在这种情况下,它意味着你可以从哪里进入。结果将是刚刚从服务器获取的该分支上的提交列表。



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

  git log --all 

这将显示所有可从所有提交的提交分支机构(本地和远程跟踪)以及标签。

git log 是一个非常强大的命令,你可以根据你想要查看的内容进行基于集合的缩减。 .. 是一个很好的语法。还有 ... ,它包含了从两个指定到它们共同祖先的分支的提交。



这种历史的走向让git变得如此强大,并且能够支持如此多有趣的工作流程。

更新:



当git遇到与存储在父树中的树相同的提交时,它在合并时不会列出提交。

  git log --all --sparse 

不会排除这些提交。



请参阅 http://linux.die.net/man/1/git-log



这也可能意味着您重置分支或你的朋友做了并再次提出失去了这个参考。当你用sha1做git日志时,如果你添加了--decorate它,输出是什么?也可以尝试 git log --walk-reflogs


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

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 log and 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 is in my repo, but I don't understand how git is deciding to show me what it does when I call 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.

Can someone explain git log to me?

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:

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

解决方案

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

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).

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.

In git, fetch means get the commits from the remote but don't update any of my local branches. git pull will 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.

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 --all parameter:

git log --all

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

git log is 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.

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

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 log --all --sparse

will not exclude those commits.

see the history simplification section of 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.

这篇关于git log显示我什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆