無料のソースコード管理 (SCM: software configuration management) ソフト Git for Windows を用いて、GitHub で公開されているシンボリックリンクを含むリポジトリを、 git clone コマンドを使ってローカルに複製する手順を紹介します。
Windows 版の Git でシンボリックリンクに対応するための設定や、複製したシンボリックリンクの注意点についても紹介します。

※Git-2.49.0 (64 bit) を使用します。
※例として GitHub で公開されている denismm/dmmlib リポジトリを clone で
前回の記事
前半では、シンボリックリンクを含むリポジトリを、 git clone コマンドを使ってローカルに複製しました。
今回の後半では、そのリポジトリフォルダが正常であることの確認と、シンボリックリンクを windows で扱う際の注意点と対処法について紹介します。
シンボリックリンクを含むリポジトリの確認
前回シンボリックリンクを含むリポジトリを clone(複製)したローカルのワーキングツリーが差分を含まない正常な状態かを、git status コマンドを使って確認します。
Show the working tree status
Displays paths that have differences between the index file and the current HEAD commit, paths that have differences between the working tree and the index file, and paths in the working tree that are not tracked by Git (and are not ignored by gitignore[5]). The first are what you would commit by running
git commit
; the second and third are what you could commit by running git add before runninggit commit
.作業ツリーのステータスを表示するGit – git-status Documentation
インデックス ファイルと現在の HEAD コミットの間に差異があるパス、作業ツリーとインデックス ファイルの間に差異があるパス、Git によって追跡されない (gitignore[5] によって無視されない) 作業ツリー内のパスを表示します。 1 つ目は、git commit を実行してコミットする内容です。 2 番目と 3 番目は、git commit を実行する前に git add を実行することでコミットできるものです。
cd コマンドでリポジトリフォルダに移動して、 git status コマンドを実行すると、「nothing to commit, working tree clean(Google翻訳:コミットするものは何もなく、作業ツリーはクリーンです)」と表示され、シンボリックリンクも含めて正常に clone (複製)できたことが確認できました。

g:\Dev\Mistical>cd dmmlib
g:\Dev\Mistical\dmmlib>git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
注意点:シンボリックリンクは移動で通常のファイルに変わってしまう
シンボリックリンクを含むリポジトリを clone (複製) したあとに、そのシンボリックリンクやそれを含むフォルダを移動すると、シンボリックリンクが参照先の内容を持つファイルに変わってしまいます。

シンボリックリンクの lines.ps も移動すると種類が .symlink から PSファイルに変わっています。
内容も、シンボリックリンクではなく、シンボリックリンクが指していたファイルの内容に置き換わっています。

対処法:設置場所でシンボリックリンク対応のクローン(複製)を実行
シンボリックリンクは移動すると、参照先の内容を持つファイルに変わってしまうので、移動せずに済むように最初から配置する場所で git clone コマンドを実行して、リポジトリを複製しましょう。

g:\Dev\Mistical\dmmlib>cd ..\mystical_ps-main\mystical_ps-main
g:\Dev\Mistical\mystical_ps-main\mystical_ps-main>git clone -c core.symlinks=true https://github.com/denismm/dmmlib.git
fatal: destination path 'dmmlib' already exists and is not an empty directory.
g:\Dev\Mistical\mystical_ps-main\mystical_ps-main>git clone -c core.symlinks=true https://github.com/denismm/dmmlib.git
Cloning into 'dmmlib'...
remote: Enumerating objects: 414, done.
remote: Counting objects: 100% (207/207), done.
remote: Compressing objects: 100% (123/123), done.
remote: Total 414 (delta 120), reused 165 (delta 80), pack-reused 207 (from 1)
Receiving objects: 100% (414/414), 859.71 KiB | 7.41 MiB/s, done.
Resolving deltas: 100% (216/216), done.
例えば、GitHub の denismm/mystical_ps では、サブフォルダに先ほどの denismm/dmmlib を配置する必要があるので、 mystical_ps のリポジトリを複製した後、そのリポジトリフォルダ内に cd コマンドで移動してからシンボリックリンクを含むリポジトリを clone (複製) します。

まとめ
前回から引き続き、無料のソースコード管理 (SCM: software configuration management) ソフト Git for Windows を用いて、GitHub で公開されているシンボリックリンクを含むリポジトリを、 git clone コマンドを使ってローカルに複製する手順を紹介しました。
Windows 版の Git でシンボリックリンクに対応するための設定や、複製したシンボリックリンクの注意点についても紹介しました。
参照サイト Thank You!
- Git
- Git – git-config Documentation #coresymlinks
- Git – git-config Documentation
- denismm/mystical_ps
- denismm/dmmlib: Library of convenient postscript functions
- Git for Windowsでシンボリックリンクを扱えるようにする #Symlink – Qiita
記事一覧 → Compota-Soft-Press
コメント