如何列出给定目录的git日志

时间:2017-07-12 17:00:32

标签: git

我想从当前目录显示git log,而repo位于不同的目录中。

例如我在/ tmp / fake_git /

中有git存储库
:~$ cd /tmp/fake_git/
:/tmp/fake_git$ git log
commit edb15e07c007237c8c06fefbb5ffd8168f4ee3d7
[...] And so on it works

但是当我尝试从其他目录中执行此操作时,它不会

:~$ cd /
:/$ git log /tmp/fake_git/
fatal: Not a git repository (or any of the parent directories): .git
:/$ git log -- /tmp/fake_git/
fatal: Not a git repository (or any of the parent directories): .git
:~$

1 个答案:

答案 0 :(得分:0)

您希望使用-C参数来调用git,就像从其他位置调用git一样。

git -C /tmp/fake_git/ log

来自git(1)

  -C <path>
       Run as if git was started in <path> instead of the current working
       directory. When multiple -C options are given, each subsequent
       non-absolute -C <path> is interpreted relative to the preceding -C
       <path>.

      This option affects options that expect path name like --git-dir and
       --work-tree in that their interpretations of the path names would be
       made relative to the working directory caused by the -C option. For
       example the following invocations are equivalent:

          git --git-dir=a.git --work-tree=b -C c status
           git --git-dir=c/a.git --work-tree=c/b status