Gitのリビジョン指定でWindows式のパスは使用できない
前に作成したKritaのGitドッカーが手持ちのWindowsで使用できないという問題を調査していたところ,どうやらgit show
でWindows式のパスを指定していたけれども,リビジョンには存在しないというエラーが出た。
実験してみた。以下はWindowsのcmd.exe
上で実行している。
C:\msys64\home\Hiroki>mkdir foo C:\msys64\home\Hiroki>cd foo C:\msys64\home\Hiroki\foo>git init Initialized empty Git repository in C:/msys64/home/Hiroki/foo/.git/ C:\msys64\home\Hiroki\foo>mkdir bar C:\msys64\home\Hiroki\foo>echo 'baz' > bar\baz C:\msys64\home\Hiroki\foo>git add bar C:\msys64\home\Hiroki\foo>git commit -m foo [master (root-commit) a311e58] foo 1 file changed, 1 insertion(+) create mode 100644 bar/baz C:\msys64\home\Hiroki\foo>git log commit a311e58569f7d69c52fe488f795ebdc5ccac32db (HEAD -> master) Author: Hiroki Tokunaga <***> Date: Mon Jun 20 02:15:22 2022 +0900 foo C:\msys64\home\Hiroki\foo>git show a311e:bar\baz fatal: path 'bar\baz' exists on disk, but not in 'a311e' C:\msys64\home\Hiroki\foo>git show a311e:bar/baz 'baz'
確かにbar\baz
だとgit show
でファイルの中身を出力できないが,bar/baz
だと出力できている。
git show --help
によれば,git show
の形式は以下のようになっている。
git show [<options>] [<object>…]
ここでobject
は,
<object>…
The names of objects to show (defaults to HEAD). For a more complete list of ways to spell object names, see "SPECIFYING REVISIONS" section in gitrevisions(7).
ということでgitrevisionsのページを見てみる。
<rev>:<path>, e.g. HEAD:README, master:./README
A suffix : followed by a path names the blob or tree at the given path in the tree-ish object named by the part before the colon. A path starting with ./ or ../ is relative to the current working directory. The given path will be converted to be relative to the working tree’s root directory. This is most useful to address a blob or tree from a commit or tree that has the same tree structure as the working tree.
特にパスの仕様に関する記述はなかったが,e.g.のmaster:./README
からわかるように,パスの区切りとして/
を使用している。