LoginSignup
7
5

More than 5 years have passed since last update.

Git管理外のディレクトリからGitリポジトリを操作する方法

Posted at

コマンドラインで操作している分には必要になるケースは少ないけど、スクリプトの中で使おうとした時に必要になったので。

Gitコマンドで例えばログを見ようとした時、カレントディレクトリがそのリポジトリディレクトリ下であれば、問題なく git log できる。

これが、別のリポジトリディレクトリから git log しようとすると、

 % git log ../hoge-repo
fatal: ../hoge-repo: '../hoge-repo' is outside repository

って言われたり、Git管理下のディレクトリでなければ、

 % git log /path/to/hoge-repo
fatal: Not a git repository (or any of the parent directories): .git

って言われたりする。

カレントディレクトリに関係なくgitコマンドを発行する場合は、以下のようにする。

git --work-tree=/path/to/hoge-repo --git-dir=/path/to/hoge-repo/.git log

Gitのバージョン次第では使えないみたいなので、使っているGitのバージョンに注意する必要あり。

参考

How can I use full paths in git? - Stack Overflow

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5