2
0

More than 1 year has passed since last update.

【Git】リポジトリのルートを取得する方法

Posted at

リポジトリルート

リポジトリルートの絶対パスを取得するには次のコマンドを実行します。

git rev-parse --show-toplevel

.git

また次のコマンドを実行すると.gitのパスを取得できます。

git rev-parse --git-dir

環境変数GIT_DIRが設定されている場合にはGIT_DIRの値が出力されます。
リポジトリルートで実行すると.gitのみが出力されそれ以外の場合には.gitの絶対パスが出力されます。

.git/*

また次のコマンドを実行すると.git内のファイルやディレクトリのパスを取得できます。

git rev-parse --git-path 取得したいファイルなどのパス

以下のように実行すると.git/info/excludeのカレントディレクトリからの相対パスを取得できます。

$ git rev-parse --git-path info/exclude
../.git/info/exclude
2
0
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
2
0