2

I would like to display git log from my current directory, while repo is located in different directory.

For example I have git repository in /tmp/fake_git/

:~$ cd /tmp/fake_git/
:/tmp/fake_git$ git log
commit edb15e07c007237c8c06fefbb5ffd8168f4ee3d7
[...] And so on it works

But when I try to do it from other directory it doesn't

:~$ 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
:~$
Emiter
  • 268
  • 2
  • 13

1 Answers1

2

You want to use the -C argument to call git as if it was called from a different location.

git -C /tmp/fake_git/ log

From 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
Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
  • Ok. Thanks for quick response. That works fine and I can add some more argument like: `git -C /tmp/fake_git/.git/ log --numstat` – Emiter Jul 12 '17 at 17:07