1. 概要
タイトルの通りです。
理由は、 GitHub リポジトリから直接ブランチ名を指定して pip install
する時に、シャープ "#" があると install できないからです。
2. 実行例
2-1. ダメな例
例えば、 pip install "git+https://github.com/username/repository-name.git@issue#15"
のように、@
以下のブランチ名のところに、#
の入っているブランチ名を指定すると、以下のように失敗します。
$ pip install "git+https://github.com/username/repository-name.git@issue#15"
Collecting git+https://github.com/username/repository-name.git@issue#15
Cloning https://github.com/username/repository-name.git (to revision issue) to /tmp/pip-req-build-mhfc7612
Running command git clone --filter=blob:none --quiet https://github.com/username/repository-name.git /tmp/pip-req-build-mhfc7612
WARNING: Did not find branch or tag 'issue', assuming revision or ref.
Running command git checkout -q issue
error: pathspec 'issue' did not match any file(s) known to git
error: subprocess-exited-with-error
× git checkout -q issue did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× git checkout -q issue did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
2-2. うまくいく例
ところが、ブランチ名を変えて、例えば #
の部分を -
などに変えてあげるとうまくいきます。
こんな感じ
pip install "git+https://github.com/username/repository-name.git@issue-15"
# 先にブランチ名を変えて、新しいブランチを GitHub に push しておく
$ git branch -m issue#15 issue-15
$ git push origin issue-15
# 新しい名称の branch を指定する
$ pip install "git+https://github.com/username/repository-name.git@issue-15"
たったこれだけなのですが、ずっと上手くいかなかった pip install
が成功するようになりました。
3. 原因
元々は issue#15
というブランチ名を指定していたつもりなのですが、エラーメッセージを見ると以下のように書かれていたので、
WARNING: Did not find branch or tag 'issue', assuming revision or ref.
おそらくですが、 #
は、 python でいうところの「予約語」のようなものに該当するのではないでしょうか。
そのため、#
以降が無視されて、その手前の部分のみの名称 (issue
という名前) のブランチを GitHub 上で探してしまい、結果的にはブランチが見つからずじまいになってしまっていました。
4. あとがき
これまで私はずっと branch 名に #
を使ってきましたが、「もう2度と使わないぞ」と思うようになりましたとさ...(´^ω^`)