【git】削除したいブランチがnot foundとなる。
Q&A
Closed
git上でとあるブランチを削除したい
git上で,
git branch
で確認できるpassword-resetブランチを削除しようと,
git branch -d password-reset
を実行すると,
error: branch 'password-reset' not found.
となってしまい,ブランチを削除できません。
Q&A
Closed
git上で,
git branch
で確認できるpassword-resetブランチを削除しようと,
git branch -d password-reset
を実行すると,
error: branch 'password-reset' not found.
となってしまい,ブランチを削除できません。
以下のように制御文字が入っているか確認してもてはどうでしょうか
git branch | cat -A
または
git branch | hexdump -C
@meb4427
Questioner
制御文字を入れるのはprintfコマンドを使うのがよいです
git branch -d `printf '\xe3\x80\x80password-reset'`
printfを使うと同じように表示されるので上記ので消えると思うのですが
$ echo `printf '\xe3\x80\x80password-reset'` | cat -A
M-cM-^@M-^@password-reset$
$
git branch
の出力でブランチ名は行頭が揃うはずですが、 password-reset
が1文字の半分ほど右にずれています。 password-reset
の実際のブランチ名は先頭に何か不可視の空白文字を含んでいるようです。削除するにはその空白文字込みでブランチ名を指定する必要があります。
git '\[branch' .git/config
を実行すると、以下のようにダブルクオート付きでブランチ名が表示されます。ブランチ名をダブルクオートごとコピーして git branch -d
に与えると削除できると思います。
$ grep '\[branch' .git/config
[branch "master"]
[branch "(空白文字)password-reset"]
$ git branch -d "(空白文字)password-reset"
@meb4427
Questioner
@meb4427
Questioner
このような半角スペースよりも更に小さい空白文字ですが,これはどのような入力が原因なのでしょうか。
バイト列 \xe3\x80\x80
は全角スペース文字を表します。ターミナル上では何かの理由で狭く表示されているようですが。ブランチを作るとき全角スペースが入ったのでしょう。
@meb4427
Questioner