今ファイルサーバーに GIT LFS のレポジトリをつくると嵌ります 

# お忙しい方へ

2022年7月現在の状況です。

ファイルサーバーにつくったベアレポジトリからクローン出来ない場合、
**Git Bash 以外で**これを実行して設定を変えてみてください。
LFSを使ってないなら無関係です。

```
git config --global --add safe.directory ///DESKTOP-H1DAY/myremote/remote.git
```

DESKTOP-H1DAYがファイルサーバーの名前。前に３本線///で正しいです。Git Bashの場合は4本線////です。
remote.gitがベアレポジトリです。


原因はこの件です。→  [CVE-2022-24765](https://forest.watch.impress.co.jp/docs/news/1402486.html)
なので22年4月以降の新しいバージョンで起きます。```git version 2.37.1.windows.1```

# 状況
このようにウィンドウズのファイルサーバー（&yen;&yen;DESKTOP-H1DAY）にベアレポジトリを置いていて、

```
PS C:\work\temp\local> git lfs env
git version 2.37.1.windows.1
git-lfs/3.2.0

Endpoint=file:////DESKTOP-H1DAY/myremote/remote.git (auth=none)
LocalWorkingDir=C:\work\temp\local
LfsStorageDir=C:\work\temp\local\.git\lfs
```

ローカル(C:\work\temp\local)にクローンしようとしていました。

```
PS C:\work\temp> git clone  file:////DESKTOP-H1DAY/myremote/remote.git local
```

# 寄り道

・ベアレポジトリとは。

https://qiita.com/devzooiiooz/items/56a02342d9d65d79f6c3

・そもそも、通常のgitの機能だけなら ```git clone \\DESKTOP-H1DAY\myremote\remote.git local``` のようにUNCでいいのに、LFSを使う場合は  ```git clone  file:////DESKTOP-H1DAY/myremote/remote.git local``` のように```file:////```（ここでは４本！）をつけてURLにしないといけないのもの嵌りポイント。

https://github.com/git-lfs/git-lfs/discussions/4635


# クローンしようとするとエラー

GIT LFS の機能でバイナリファイルをダウンロードするところでSmudge error が出ます。
抜粋するとこんな感じなのです。ググってもヒットせず。

```
18:55:04.294469 trace git-lfs: xfer[git-lfs]: 18:55:04.294469 trace git-lfs: exec: git 'rev-parse' '--git-dir'
18:55:04.332857 trace git-lfs: xfer[git-lfs]: error creating handler: failed to call `git rev-parse --git-dir`: exit status 128
18:55:04.333919 trace git-lfs: xfer: Aborting worker process: 0
Error downloading object: image.png (bf4b01c): Smudge error: Error downloading image.png (bf4b01c4837fc9b0366162dd9d0af2fc41ac5773aab9be49dbdcecdd5c3a8f03): EOF
```


<details><summary>ログ（クリックで展開） </summary><div>

```
PS C:\work\temp> $env:GIT_CURL_VERBOSE=1
PS C:\work\temp> $env:GIT_TRANSFER_TRACE=1
PS C:\work\temp> $env:GIT_TRACE=1
PS C:\work\temp> git clone  file:////DESKTOP-H1DAY/myremote/remote.git local
18:55:02.429013 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
18:55:02.430040 git.c:460               trace: built-in: git clone file:////DESKTOP-H1DAY/myremote/remote.git local
Cloning into 'local'...
18:55:02.453013 run-command.c:654       trace: run_command: unset GIT_DIR; GIT_PROTOCOL=version=2 'git-upload-pack '\''//DESKTOP-H1DAY/myremote/remote.git'\'''
18:55:02.510432 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
18:55:02.511405 git.c:460               trace: built-in: git upload-pack //DESKTOP-H1DAY/myremote/remote.git
18:55:02.565817 run-command.c:654       trace: run_command: git pack-objects --revs --thin --stdout --progress --delta-base-offset
18:55:02.572820 run-command.c:654       trace: run_command: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 7524 on DESKTOP-H1DAY' --check-self-contained-and-connected
remote: 18:55:02.579822 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core18:55:02.584819 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core

18:55:02.586818 git.c:460               trace: built-in: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 7524 on DESKTOP-H1DAY' --check-self-contained-and-connected
remote: 18:55:02.590918 git.c:460               trace: built-in: git pack-objects --revs --thin --stdout --progress --delta-base-offset
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 9 (delta 1), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (9/9), done.
Resolving deltas: 100% (1/1), done.
18:55:02.660623 run-command.c:654       trace: run_command: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity'
18:55:02.672102 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
18:55:02.674112 git.c:460               trace: built-in: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity'
18:55:02.687923 run-command.c:654       trace: run_command: 'git-lfs filter-process'
18:55:02.748796 trace git-lfs: exec: uname
18:55:02.851578 trace git-lfs: exec: cygpath '-w' 'C:/work/temp/local/.git'
18:55:02.882956 trace git-lfs: exec: git 'version'
18:55:02.930811 trace git-lfs: exec: git '-c' 'filter.lfs.smudge=' '-c' 'filter.lfs.clean=' '-c' 'filter.lfs.process=' '-c' 'filter.lfs.required=false' 'rev-parse' '--git-dir' '--show-toplevel'
18:55:02.959305 trace git-lfs: exec: cygpath '-w' 'C:\work\temp\local\.git'
18:55:02.991064 trace git-lfs: exec: cygpath '-w' 'C:/work/temp/local'
18:55:03.021385 trace git-lfs: exec: git 'rev-parse' '--is-bare-repository'
18:55:03.051623 trace git-lfs: exec: git 'config' '--includes' '--local' 'lfs.repositoryformatversion'
18:55:03.082464 trace git-lfs: exec: git 'config' '--includes' '--replace-all' 'lfs.repositoryformatversion' '0'
18:55:03.114641 trace git-lfs: exec: cygpath '-w' 'C:\work\temp\local'
18:55:03.144613 trace git-lfs: exec: git 'config' '--includes' '-l'
18:55:03.175480 trace git-lfs: exec: git 'rev-parse' '--is-bare-repository'
18:55:03.205839 trace git-lfs: exec: git 'config' '--includes' '-l' '--blob' ':.lfsconfig'
18:55:03.236828 trace git-lfs: exec: git 'config' '--includes' '-l' '--blob' 'HEAD:.lfsconfig'
18:55:03.267612 trace git-lfs: Install hook: pre-push, force=false, path=C:\work\temp\local\.git\hooks\pre-push
18:55:03.268588 trace git-lfs: Install hook: post-checkout, force=false, path=C:\work\temp\local\.git\hooks\post-checkout
18:55:03.269131 trace git-lfs: Install hook: post-commit, force=false, path=C:\work\temp\local\.git\hooks\post-commit
18:55:03.269780 trace git-lfs: Install hook: post-merge, force=false, path=C:\work\temp\local\.git\hooks\post-merge
18:55:03.269780 trace git-lfs: Initialize filter-process
18:55:03.270972 trace git-lfs: exec: git '-c' 'filter.lfs.smudge=' '-c' 'filter.lfs.clean=' '-c' 'filter.lfs.process=' '-c' 'filter.lfs.required=false' 'rev-parse' 'HEAD' '--symbolic-full-name' 'HEAD'
18:55:03.298447 trace git-lfs: tq: running as batched queue, batch size of 100
18:55:03.300828 trace git-lfs: filepathfilter: accepting "image.png"
18:55:03.301775 trace git-lfs: tq: sending batch of size 1
18:55:03.302285 trace git-lfs: tq: starting transfer adapter "lfs-standalone-file"
18:55:03.302401 trace git-lfs: xfer: adapter "lfs-standalone-file" Begin() with 1 workers
18:55:03.302401 trace git-lfs: xfer: starting up custom transfer process "lfs-standalone-file" for worker 0
18:55:03.305548 trace git-lfs: exec: sh '-c' 'git-lfs standalone-file'
18:55:03.307742 trace git-lfs: xfer: Custom adapter worker 0 sending message: {"event":"init","operation":"download","remote":"origin","concurrent":false,"concurrenttransfers":8}
18:55:03.393223 trace git-lfs: xfer[git-lfs]: 18:55:03.357959 trace git-lfs: exec: uname
18:55:03.454676 trace git-lfs: xfer[git-lfs]: 18:55:03.454676 trace git-lfs: exec: cygpath '-w' 'C:\work\temp\local\.git'
18:55:03.485287 trace git-lfs: xfer[git-lfs]: 18:55:03.485287 trace git-lfs: exec: git 'version'
18:55:03.531849 trace git-lfs: xfer[git-lfs]: 18:55:03.531849 trace git-lfs: exec: git '-c' 'filter.lfs.smudge=' '-c' 'filter.lfs.clean=' '-c' 'filter.lfs.process=' '-c' 'filter.lfs.required=false' 'rev-parse' '--git-dir' '--show-toplevel'
18:55:03.563162 trace git-lfs: xfer[git-lfs]: 18:55:03.563162 trace git-lfs: exec: cygpath '-w' 'C:\work\temp\local\.git'
18:55:03.594608 trace git-lfs: xfer[git-lfs]: 18:55:03.594429 trace git-lfs: exec: cygpath '-w' 'C:/work/temp/local'
18:55:03.623925 trace git-lfs: xfer[git-lfs]: 18:55:03.623345 trace git-lfs: exec: git 'config' '--includes' '-l'
18:55:03.654154 trace git-lfs: xfer[git-lfs]: 18:55:03.654039 trace git-lfs: exec: git 'rev-parse' '--is-bare-repository'
18:55:03.684362 trace git-lfs: xfer[git-lfs]: 18:55:03.684252 trace git-lfs: exec: git 'config' '--includes' '-l' '--blob' ':.lfsconfig'
18:55:03.715393 trace git-lfs: xfer[git-lfs]: 18:55:03.715274 trace git-lfs: exec: git 'config' '--includes' '-l' '--blob' 'HEAD:.lfsconfig'
18:55:03.747564 trace git-lfs: xfer[git-lfs]: 18:55:03.746959 trace git-lfs: exec: cygpath '-w' '//DESKTOP-H1DAY/myremote/remote.git'
18:55:03.784313 trace git-lfs: xfer[git-lfs]: 18:55:03.783808 trace git-lfs: exec: git 'rev-parse' '--git-dir'
18:55:03.823492 trace git-lfs: xfer[git-lfs]: error creating handler: failed to call `git rev-parse --git-dir`: exit status 128
18:55:03.824611 trace git-lfs: xfer: Aborting worker process: 0
18:55:03.825378 trace git-lfs: tq: running as batched queue, batch size of 100
18:55:03.825910 trace git-lfs: filepathfilter: accepting "image.png"
Downloading image.png (32 KB)
18:55:03.826548 trace git-lfs: tq: running as batched queue, batch size of 100
18:55:03.827051 trace git-lfs: tq: sending batch of size 1
18:55:03.827274 trace git-lfs: tq: starting transfer adapter "lfs-standalone-file"
18:55:03.827490 trace git-lfs: xfer: adapter "lfs-standalone-file" Begin() with 1 workers
18:55:03.827715 trace git-lfs: xfer: starting up custom transfer process "lfs-standalone-file" for worker 0
18:55:03.829621 trace git-lfs: exec: sh '-c' 'git-lfs standalone-file'
18:55:03.831929 trace git-lfs: xfer: Custom adapter worker 0 sending message: {"event":"init","operation":"download","remote":"origin","concurrent":false,"concurrenttransfers":8}
18:55:03.913080 trace git-lfs: xfer[git-lfs]: 18:55:03.882086 trace git-lfs: exec: uname
18:55:03.965241 trace git-lfs: xfer[git-lfs]: 18:55:03.965119 trace git-lfs: exec: cygpath '-w' 'C:\work\temp\local\.git'
18:55:03.994663 trace git-lfs: xfer[git-lfs]: 18:55:03.994494 trace git-lfs: exec: git 'version'
18:55:04.041516 trace git-lfs: xfer[git-lfs]: 18:55:04.041516 trace git-lfs: exec: git '-c' 'filter.lfs.smudge=' '-c' 'filter.lfs.clean=' '-c' 'filter.lfs.process=' '-c' 'filter.lfs.required=false' 'rev-parse' '--git-dir' '--show-toplevel'
18:55:04.072938 trace git-lfs: xfer[git-lfs]: 18:55:04.072819 trace git-lfs: exec: cygpath '-w' 'C:\work\temp\local\.git'
18:55:04.104373 trace git-lfs: xfer[git-lfs]: 18:55:04.104274 trace git-lfs: exec: cygpath '-w' 'C:/work/temp/local'
18:55:04.133685 trace git-lfs: xfer[git-lfs]: 18:55:04.133557 trace git-lfs: exec: git 'config' '--includes' '-l'
18:55:04.166406 trace git-lfs: xfer[git-lfs]: 18:55:04.166406 trace git-lfs: exec: git 'rev-parse' '--is-bare-repository'
18:55:04.195428 trace git-lfs: xfer[git-lfs]: 18:55:04.195287 trace git-lfs: exec: git 'config' '--includes' '-l' '--blob' ':.lfsconfig'
18:55:04.226318 trace git-lfs: xfer[git-lfs]: 18:55:04.226318 trace git-lfs: exec: git 'config' '--includes' '-l' '--blob' 'HEAD:.lfsconfig'
18:55:04.258812 trace git-lfs: xfer[git-lfs]: 18:55:04.258812 trace git-lfs: exec: cygpath '-w' '//DESKTOP-H1DAY/myremote/remote.git'
18:55:04.294469 trace git-lfs: xfer[git-lfs]: 18:55:04.294469 trace git-lfs: exec: git 'rev-parse' '--git-dir'
18:55:04.332857 trace git-lfs: xfer[git-lfs]: error creating handler: failed to call `git rev-parse --git-dir`: exit status 128
18:55:04.333919 trace git-lfs: xfer: Aborting worker process: 0
Error downloading object: image.png (bf4b01c): Smudge error: Error downloading image.png (bf4b01c4837fc9b0366162dd9d0af2fc41ac5773aab9be49dbdcecdd5c3a8f03): EOF

Errors logged to 'C:\work\temp\local\.git\lfs\logs\20220723T185504.3344718.log'.
Use `git lfs logs last` to view the log.
error: external filter 'git-lfs filter-process' failed
fatal: image.png: smudge filter lfs failed
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry with 'git restore --source=HEAD :/'
```
</div></details>

# 原因

原因はこの件への対策です。→  [CVE-2022-24765](https://forest.watch.impress.co.jp/docs/news/1402486.html)

> この問題は「Git」がトップレベルの「.git」ディレクトリを探す際、所有者をチェックする処理を加えることで解決されている。

所有者がカレントディレクトリと違うディレクトリでgitのコマンドが動作しないようになったらしいです。
この「所有権」はフォルダのプロパティ＞セキュリティにある「フル コントロール」のことではないです。


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1017728/6ba7c6df-f274-f86c-17e6-a9d1e80610cc.png)

詳細設定にある所有者のことです。フォルダを作った人につけられるます。
こんなところ見てるのか。。。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1017728/c02bb7ee-c47e-971e-6b4c-e67f4bccfc29.png)

# 対策

リモートのベアレポジトリが安全だとわかっているなら、こちらを実行します。

```
git config --global --add safe.directory ///DESKTOP-H1DAY/myremote/remote.git
```

ここではcloneのときと違って、```/```が3本。。。難しい。↓こちらのように混乱が生じている。

https://github.com/git-for-windows/git/issues/3786


煩わしいことにGit Bash の場合はパスを勝手に変えるのを逆算して4本にしておきます。


なので、携わるリモートレポジトリがいつも安全だとわかっているなら```*```がシンプルでよいです。

```
git config --global --add safe.directory *
```

設定変更後にクローンしたらうまくいきました。

<details><summary>成功時のログ（クリックで展開） </summary><div>

```
PS C:\work\temp> git config --global --add safe.directory ///DESKTOP-H1DAY/myremote/remote.git
05:27:37.731869 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
05:27:37.733877 git.c:460               trace: built-in: git config --global --add safe.directory ///DESKTOP-H1DAY/myremote/remote.git
PS C:\work\temp> git clone  file:////DESKTOP-H1DAY/myremote/remote.git local
05:27:51.321386 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
05:27:51.322372 git.c:460               trace: built-in: git clone file:////DESKTOP-H1DAY/myremote/remote.git local
Cloning into 'local'...
05:27:51.352389 run-command.c:654       trace: run_command: unset GIT_DIR; GIT_PROTOCOL=version=2 'git-upload-pack '\''//DESKTOP-H1DAY/myremote/remote.git'\'''
05:27:51.410361 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
05:27:51.415361 git.c:460               trace: built-in: git upload-pack //DESKTOP-H1DAY/myremote/remote.git
05:27:51.470224 run-command.c:654       trace: run_command: git pack-objects --revs --thin --stdout --progress --delta-base-offset
05:27:51.476225 run-command.c:654       trace: run_command: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 17768 on DESKTOP-H1DAY' --check-self-contained-and-connected
05:27:51.492228 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
05:27:51.494222 git.c:460               trace: built-in: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 17768 on DESKTOP-H1DAY' --check-self-contained-and-connected
remote: 05:27:51.484219 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
remote: 05:27:51.496980 git.c:460               trace: built-in: git pack-objects --revs --thin --stdout --progress --delta-base-offset
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 9 (delta 1), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (9/9), done.
Resolving deltas: 100% (1/1), done.
05:27:51.575421 run-command.c:654       trace: run_command: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity'
05:27:51.588418 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
05:27:51.591419 git.c:460               trace: built-in: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity'
05:27:51.606448 run-command.c:654       trace: run_command: 'git-lfs filter-process'
05:27:51.666656 trace git-lfs: exec: uname
05:27:51.753299 trace git-lfs: exec: cygpath '-w' 'C:/work/temp/local/.git'
05:27:51.782459 trace git-lfs: exec: git 'version'
05:27:51.829514 trace git-lfs: exec: git '-c' 'filter.lfs.smudge=' '-c' 'filter.lfs.clean=' '-c' 'filter.lfs.process=' '-c' 'filter.lfs.required=false' 'rev-parse' '--git-dir' '--show-toplevel'
05:27:51.861168 trace git-lfs: exec: cygpath '-w' 'C:\work\temp\local\.git'
05:27:51.892328 trace git-lfs: exec: cygpath '-w' 'C:/work/temp/local'
05:27:51.921535 trace git-lfs: exec: git 'rev-parse' '--is-bare-repository'
05:27:51.955236 trace git-lfs: exec: git 'config' '--includes' '--local' 'lfs.repositoryformatversion'
05:27:51.982759 trace git-lfs: exec: git 'config' '--includes' '--replace-all' 'lfs.repositoryformatversion' '0'
05:27:52.015137 trace git-lfs: exec: cygpath '-w' 'C:\work\temp\local'
05:27:52.044271 trace git-lfs: exec: git 'config' '--includes' '-l'
05:27:52.074422 trace git-lfs: exec: git 'rev-parse' '--is-bare-repository'
05:27:52.105729 trace git-lfs: exec: git 'config' '--includes' '-l' '--blob' ':.lfsconfig'
05:27:52.137295 trace git-lfs: exec: git 'config' '--includes' '-l' '--blob' 'HEAD:.lfsconfig'
05:27:52.167728 trace git-lfs: Install hook: pre-push, force=false, path=C:\work\temp\local\.git\hooks\pre-push
05:27:52.168814 trace git-lfs: Install hook: post-checkout, force=false, path=C:\work\temp\local\.git\hooks\post-checkout
05:27:52.169237 trace git-lfs: Install hook: post-commit, force=false, path=C:\work\temp\local\.git\hooks\post-commit
05:27:52.169787 trace git-lfs: Install hook: post-merge, force=false, path=C:\work\temp\local\.git\hooks\post-merge
05:27:52.170375 trace git-lfs: Initialize filter-process
05:27:52.171489 trace git-lfs: exec: git '-c' 'filter.lfs.smudge=' '-c' 'filter.lfs.clean=' '-c' 'filter.lfs.process=' '-c' 'filter.lfs.required=false' 'rev-parse' 'HEAD' '--symbolic-full-name' 'HEAD'
05:27:52.198878 trace git-lfs: tq: running as batched queue, batch size of 100
05:27:52.200133 trace git-lfs: filepathfilter: accepting "image.png"
05:27:52.202038 trace git-lfs: tq: sending batch of size 1
05:27:52.202038 trace git-lfs: tq: starting transfer adapter "lfs-standalone-file"
05:27:52.202038 trace git-lfs: xfer: adapter "lfs-standalone-file" Begin() with 1 workers
05:27:52.202654 trace git-lfs: xfer: starting up custom transfer process "lfs-standalone-file" for worker 0
05:27:52.204576 trace git-lfs: exec: sh '-c' 'git-lfs standalone-file'
05:27:52.206875 trace git-lfs: xfer: Custom adapter worker 0 sending message: {"event":"init","operation":"download","remote":"origin","concurrent":false,"concurrenttransfers":8}
05:27:52.287624 trace git-lfs: xfer[git-lfs]: 05:27:52.256615 trace git-lfs: exec: uname
05:27:52.339813 trace git-lfs: xfer[git-lfs]: 05:27:52.339813 trace git-lfs: exec: cygpath '-w' 'C:\work\temp\local\.git'
05:27:52.369437 trace git-lfs: xfer[git-lfs]: 05:27:52.369287 trace git-lfs: exec: git 'version'
05:27:52.418307 trace git-lfs: xfer[git-lfs]: 05:27:52.418307 trace git-lfs: exec: git '-c' 'filter.lfs.smudge=' '-c' 'filter.lfs.clean=' '-c' 'filter.lfs.process=' '-c' 'filter.lfs.required=false' 'rev-parse' '--git-dir' '--show-toplevel'
05:27:52.447745 trace git-lfs: xfer[git-lfs]: 05:27:52.447240 trace git-lfs: exec: cygpath '-w' 'C:\work\temp\local\.git'
05:27:52.477972 trace git-lfs: xfer[git-lfs]: 05:27:52.477972 trace git-lfs: exec: cygpath '-w' 'C:/work/temp/local'
05:27:52.508040 trace git-lfs: xfer[git-lfs]: 05:27:52.507533 trace git-lfs: exec: git 'config' '--includes' '-l'
05:27:52.539024 trace git-lfs: xfer[git-lfs]: 05:27:52.538481 trace git-lfs: exec: git 'rev-parse' '--is-bare-repository'
05:27:52.570773 trace git-lfs: xfer[git-lfs]: 05:27:52.570773 trace git-lfs: exec: git 'config' '--includes' '-l' '--blob' ':.lfsconfig'
05:27:52.602187 trace git-lfs: xfer[git-lfs]: 05:27:52.602187 trace git-lfs: exec: git 'config' '--includes' '-l' '--blob' 'HEAD:.lfsconfig'
05:27:52.635633 trace git-lfs: xfer[git-lfs]: 05:27:52.635633 trace git-lfs: exec: cygpath '-w' '//DESKTOP-H1DAY/myremote/remote.git'
05:27:52.672664 trace git-lfs: xfer[git-lfs]: 05:27:52.672664 trace git-lfs: exec: git 'rev-parse' '--git-dir'
05:27:52.719495 trace git-lfs: xfer[git-lfs]: 05:27:52.719495 trace git-lfs: exec: cygpath '-w' '.'
05:27:52.759497 trace git-lfs: xfer[git-lfs]: 05:27:52.759497 trace git-lfs: using "\\\\DESKTOP-H1DAY\\myremote\\remote.git" as remote git directory
05:27:52.759497 trace git-lfs: xfer: Custom adapter worker 0 received response: {}
05:27:52.760008 trace git-lfs: xfer: started custom adapter process "git-lfs" for worker 0 OK
05:27:52.760664 trace git-lfs: xfer: adapter "lfs-standalone-file" started
05:27:52.760762 trace git-lfs: xfer: adapter "lfs-standalone-file" worker 0 starting
05:27:52.760762 trace git-lfs: xfer: adapter "lfs-standalone-file" worker 0 processing job for "bf4b01c4837fc9b0366162dd9d0af2fc41ac5773aab9be49dbdcecdd5c3a8f03"
05:27:52.761272 trace git-lfs: xfer: Custom adapter worker 0 sending message: {"event":"download","oid":"bf4b01c4837fc9b0366162dd9d0af2fc41ac5773aab9be49dbdcecdd5c3a8f03","size":32038,"action":null}
05:27:52.762183 trace git-lfs: xfer[git-lfs]: 05:27:52.762021 trace git-lfs: exec: git 'config' '--includes' '-l'
05:27:52.804900 trace git-lfs: xfer[git-lfs]: 05:27:52.804790 trace git-lfs: exec: git 'rev-parse' '--is-bare-repository'
05:27:52.836372 trace git-lfs: xfer[git-lfs]: 05:27:52.836372 trace git-lfs: exec: git 'config' '--includes' '-l' '--blob' ':.lfsconfig'
05:27:52.882234 trace git-lfs: xfer[git-lfs]: 05:27:52.881730 trace git-lfs: exec: git 'config' '--includes' '-l' '--blob' 'HEAD:.lfsconfig'
05:27:52.940094 trace git-lfs: xfer: Custom adapter worker 0 received response: {"event":"complete","oid":"bf4b01c4837fc9b0366162dd9d0af2fc41ac5773aab9be49dbdcecdd5c3a8f03","path":"C:\\work\\temp\\local\\.git\\lfs\\tmp\\lfs-standalone-file-3109751015\\download4099616091"}
05:27:52.943891 trace git-lfs: xfer: adapter "lfs-standalone-file" worker 0 finished job for "bf4b01c4837fc9b0366162dd9d0af2fc41ac5773aab9be49dbdcecdd5c3a8f03"
05:27:52.943891 trace git-lfs: xfer: adapter "lfs-standalone-file" End()
05:27:52.943891 trace git-lfs: xfer: adapter "lfs-standalone-file" worker 0 stopping
05:27:52.943891 trace git-lfs: xfer: Shutting down adapter worker 0
05:27:52.944404 trace git-lfs: xfer: Custom adapter worker 0 sending message: {"event":"terminate"}
05:27:52.944962 trace git-lfs: xfer[git-lfs]: 05:27:52.944404 trace git-lfs: filepathfilter: creating pattern ".git" of type gitignore
05:27:52.944962 trace git-lfs: xfer[git-lfs]: 05:27:52.944962 trace git-lfs: filepathfilter: creating pattern "**/.git" of type gitignore
05:27:52.944962 trace git-lfs: xfer[git-lfs]: 05:27:52.944962 trace git-lfs: filepathfilter: accepting "tmp"
05:27:52.944962 trace git-lfs: filepathfilter: accepting "image.png"
05:27:52.958690 trace git-lfs: xfer: adapter "lfs-standalone-file" stopped
05:27:52.959800 run-command.c:1553      run_processes_parallel: preparing to run up to 1 tasks
05:27:52.959800 run-command.c:654       trace: run_command: C:/work/temp/local/.git/hooks/post-checkout 0000000000000000000000000000000000000000 9e18ff928cc3c6ddcfae1a7e692403d54745f217 1
05:27:53.039808 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
05:27:53.041807 git.c:749               trace: exec: git-lfs post-checkout 0000000000000000000000000000000000000000 9e18ff928cc3c6ddcfae1a7e692403d54745f217 1
05:27:53.041807 run-command.c:654       trace: run_command: git-lfs post-checkout 0000000000000000000000000000000000000000 9e18ff928cc3c6ddcfae1a7e692403d54745f217 1
05:27:53.066891 trace git-lfs: exec: uname
05:27:53.164538 trace git-lfs: exec: cygpath '-w' 'C:/work/temp/local/.git'
05:27:53.209272 trace git-lfs: exec: git 'version'
05:27:53.255331 trace git-lfs: exec: git '-c' 'filter.lfs.smudge=' '-c' 'filter.lfs.clean=' '-c' 'filter.lfs.process=' '-c' 'filter.lfs.required=false' 'rev-parse' '--git-dir' '--show-toplevel'
05:27:53.288051 trace git-lfs: exec: cygpath '-w' 'C:\work\temp\local\.git'
05:27:53.333784 trace git-lfs: exec: cygpath '-w' 'C:/work/temp/local'
05:27:53.362584 trace git-lfs: exec: git 'config' '--includes' '-l'
05:27:53.409657 trace git-lfs: exec: git 'rev-parse' '--is-bare-repository'
05:27:53.456278 trace git-lfs: exec: git 'config' '--includes' '-l' '--blob' ':.lfsconfig'
05:27:53.502221 trace git-lfs: exec: git 'config' '--includes' '-l' '--blob' 'HEAD:.lfsconfig'
05:27:53.533308 trace git-lfs: exec: git '-c' 'filter.lfs.smudge=' '-c' 'filter.lfs.clean=' '-c' 'filter.lfs.process=' '-c' 'filter.lfs.required=false' 'rev-parse' 'HEAD' '--symbolic-full-name' 'HEAD'
05:27:53.580570 trace git-lfs: NewLsFiles: running in C:\work\temp\local git ls-files -z --cached --exclude-standard --others
05:27:53.580705 trace git-lfs: exec: git '-c' 'filter.lfs.smudge=' '-c' 'filter.lfs.clean=' '-c' 'filter.lfs.process=' '-c' 'filter.lfs.required=false' 'ls-files' '-z' '--cached' '--exclude-standard' '--others'
05:27:53.626048 trace git-lfs: findAttributeFiles: located .gitattributes
05:27:53.649219 run-command.c:1591      run_processes_parallel: done
05:27:53.649219 run-command.c:45        trace: run_command: running exit handler for pid 9256
05:27:53.649219 trace git-lfs: filepathfilter: creating pattern ".git" of type gitignore
05:27:53.650042 trace git-lfs: filepathfilter: creating pattern "**/.git" of type gitignore
05:27:53.650042 trace git-lfs: filepathfilter: accepting "tmp"
```
</div></details>

設定を消すときはこれ。複数設定されているときはwarningが出て消せない。常に全部消す。

```
git config --global --unset-all safe.directory
```

# 嵌る理由の考察（愚痴）
- そもそもベアレポジトリ＋LFS ＋作成者以外が利用なんてことをしたい人が少ないので情報が少ない。
- GITの不具合対応で仕様が変わったのだが、影響を受けたのが別チームが作るLFSなのでエラーログを見てもヒントがない。
- GITが古くてダウンロードできなかった人が最新のGITをインストールするとこの症状になる。
- 良い感じに新しすぎないバージョンのGITを使ってた（と後で発覚する）人は成功するので切り分けが難しい。
- ベアレポジトリを作った本人はフォルダの所有権をもっているので最新のGITをインストールしても症状が出ないので切り分けが難しい。
- ついでに新設定の「safe.directory」の設定方法が分かりにくい。クローンするときはfile:////DESKTOP-H1DAY/myremote/remote.git と書くのに ///DESKTOP-H1DAY/myremote/remote.gitと設定するのは辿りつかなくないか？


# まとめ

そうはいっても有難く使わせていただきます。

事情を聞いてみましたが、修正は難しそうですね。

https://github.com/git-lfs/git-lfs/issues/5081

# 参考

https://forest.watch.impress.co.jp/docs/news/1402486.html

https://www.nda.co.jp/memo/git_safe_directory/

https://github.com/git-for-windows/git/issues/3786

https://zenn.dev/1060ki/articles/322b72dbd6ce42

https://git-scm.com/book/ja/v2/Git%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC-%E3%83%97%E3%83%AD%E3%83%88%E3%82%B3%E3%83%AB

https://namespaceit.com/blog/cannot-add-parent-directory-to-safedirectory-on-git

LFSの部分だけをファイルサーバーにしたりもできるらしい。

https://tech.griphone.co.jp/2018/11/22/gitlab-to-github-sre/