備忘録やめた

備忘録として使用していたけどやめた.このブログに載せてあるコードのライセンスは別途記載がない限りWTFPL OR NYSLです.

Gitのリビジョン指定でWindows式のパスは使用できない

前に作成したKritaのGitドッカー手持ちのWindowsで使用できないという問題を調査していたところ,どうやらgit showWindows式のパスを指定していたけれども,リビジョンには存在しないというエラーが出た。

実験してみた。以下はWindowscmd.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からわかるように,パスの区切りとして/を使用している。