このブログは、旧・はてなダイアリー「檜山正幸のキマイラ飼育記 メモ編」(http://d.hatena.ne.jp/m-hiyama-memo/)のデータを移行・保存したものであり、今後(2019年1月以降)更新の予定はありません。

今後の更新は、新しいブログ http://m-hiyama-memo.hatenablog.com/ で行います。

git submoduleとmagitとgithub

magitのsubmodule addは、生コマンドより使いやすい。生コマンドの git submodule add, git submodule init, git submodule update, git submodule checkout を一度にやってくれる。だが、magit操作に慣れると、コマンドラインで慌てふためいたり途方に暮れることになりそう。

サブモジュールをマウント(add/init/updae/checkoutの一連操作をそう呼ぶことにする)して、それからgithubにpushすると、githubでは、他のリポジトリへのHTMLリンクを作る。サブモジュールは実体ではなくて、あくまで解決可能な参照だから、このUIは良いと思う。githubがサブモジュールをリンクに直すためには、.gitmodulesの情報を使っている。.git/configだけでは無理なようだ。

サブモジュールの削除はmagitで失敗。たぶん、パス指定がまずかったようだが、やり直さないでコマンドラインでやってしまった。


[PS ~\Daphnia.org\sample2]
sample2 > git submodule status
8caab7703a44ccae3c69b19d1fbc0060720a5046 content (heads/master)
8dc61b2cc0a98db5278ba10f68ed206fe0c5cf4d layouts/layouts/partials (heads/master)

[PS ~\Daphnia.org\sample2]
sample2 > git submodule deinit layouts/layouts/partials
error: the following file has changes staged in the index:
layouts/layouts/partials
(use --cached to keep the file, or -f to force removal)
Submodule work tree 'layouts/layouts/partials' contains local modifications; use '-f' to discard them

[PS ~\Daphnia.org\sample2]
sample2 > git submodule deinit -f layouts/layouts/partials
Cleared directory 'layouts/layouts/partials'
Submodule 'layouts/layouts/partials' (https://github.com/m-hiyama/hugo-common-partials.git) unregistered for path 'layouts/layouts/partials'

[PS ~\Daphnia.org\sample2]
sample2 >

パス指定が間違いやすい。

./.git/configは自動的に修正されてるが、./.gitmodulesには削除したサブモジュールが残る。おそらくこれは問題ないだろう。.gitmodulesは参考データで、実際の挙動は./.git/configで制御されていそうだ。また、git submodule deinitだけでは、サブディレクトリに配置されたファイル郡は消えない。-f すると消える。がディレクトリそのものは残る。ややこしい。


次のコマンドが成功したので、物理入れ子レポジトリの .git/ をパスに指定すると、物理入れ子ディレクトリをサブモジュールにすることは可能かもしれない。がメリットがない。


[PS ~\Daphnia.org\sample2]
sample2 > git submodule add https://github.com/m-hiyama/hugo-common-partials.git .\layout
s\partials
Adding existing repo at '.\layouts\partials' to the index

[PS ~\Daphnia.org\sample2]
sample2 >


変な挙動していると思ったら、パスにバックスラッシュが入るとスラッシュと同一視してくれない。パス正規化処理が不十分なようだ。目視確認、手動修正が必要だ。ムーーー。

[submodule "content"]
	url = https://github.com/m-hiyama/hugo-sample-content.git
[submodule "layouts/partials"]
	url = https://github.com/m-hiyama/hugo-common-partials.git
[submodule ".\\layouts\\partials"]
	url = https://github.com/m-hiyama/hugo-common-partials.git