Use git “log” command in another folder

前端 未结 2 1314
长情又很酷
长情又很酷 2020-11-28 05:37

I have some php files in a Folder A (which is a git project). In these php file I want to execute \"git log\" but for the folder B. Folder B is another git project (so log i

相关标签:
2条回答
  • 2020-11-28 05:46

    From, man git:

    You can do this with the --git-dir parameter, before passing any commands.

    git --git-dir /foo/bar/.git log
    

    (Specifying the .git directory is necessary.) From the documentation:

    --git-dir=<path>

    Set the path to the repository. This can also be controlled by setting the GIT_DIR environment variable. It can be an absolute path or relative path to current working directory.

    0 讨论(0)
  • 2020-11-28 05:51

    With git 1.8.5 (Q4 2013), you will have another choice, instead of setting --git-dir.
    If you want to execute git log in folder B, type:

    git -C B log
    

    Just like "make -C <directory>", "git -C <directory> ..." tells Git to go there before doing anything else.


    See commit 44e1e4 by Nazri Ramliy:

    It takes more keypresses to invoke git command in a different directory without leaving the current directory:

    1. (cd ~/foo && git status)
      git --git-dir=~/foo/.git --work-tree=~/foo status
      GIT_DIR=~/foo/.git GIT_WORK_TREE=~/foo git status
    2. (cd ../..; git grep foo)
    3. for d in d1 d2 d3; do (cd $d && git svn rebase); done

    The methods shown above are acceptable for scripting but are too cumbersome for quick command line invocations.

    With this new option, the above can be done with fewer keystrokes:

    1. git -C ~/foo status
    2. git -C ../.. grep foo
    3. for d in d1 d2 d3; do git -C $d svn rebase; done
    0 讨论(0)
提交回复
热议问题