これは厳密にはプログラミングの質問ではないことはわかっていますが、git に関連しています。git という名前のブランチを誤って作成して--track
しまいました (リモート ブランチをマージするときにオプションの順序が間違っていました)。
通常のコマンドは機能しません:
git branch -D "--track"
引用符とバックスラッシュでエスケープしようとしましたが、どちらも機能しません。
何か案は?
これは厳密にはプログラミングの質問ではないことはわかっていますが、git に関連しています。git という名前のブランチを誤って作成して--track
しまいました (リモート ブランチをマージするときにオプションの順序が間違っていました)。
通常のコマンドは機能しません:
git branch -D "--track"
引用符とバックスラッシュでエスケープしようとしましたが、どちらも機能しません。
何か案は?
試しましたか
git branch -D -- --track
? " --
" は通常、"その名前が何であれ、続くものはオプションではない" という規則です。
「The Art of Unix Programming」のセクション「Command-Line Options」から:
オプションの解釈を停止し、後続のすべての引数を文字どおりに処理するためのシグナルとして二重ハイフンを認識することも慣習的です。
cleartoolのような他の (必ずしも Unix 関連ではない) CLI (コマンド ライン インターフェイス) でその規則を見つけることができます。
非オプションの引数がハイフン (
–</code>) character, you may need to precede it with a double-hyphen argument, to prevent it from being interpreted as an option:
cleartool rmtype -lbtype -- -temporary_label-
The P18 (a fast and flexible file preprocessor with macro processing capabilities and special support for internationalization) mentions that also and gives a good description of the general idea behind that convention:
All option arguments passed to the commands start with a single hyphen.
All option arguments (if any) must precede all non-option arguments.
The end of the option arguments may be signaled using a double hyphen, this is useful if a non-option argument starts with a hyphen. Terminating the list of option arguments with a double hyphen works for all commands, even those that don't take any option arguments.
The OptionParser tool written in ruby also lays it out quite plainly:*
Option Parsing Termination
It is convention that a double hyphen is a signal to stop option interpretation and to read the remaining statements on the command line literally. So, a command such as:
app -- -x -y -z
will not ‘see’ the three mode-flags. Instead, they will be treated as arguments to the application:
#args = ["-x", "-y", "-z"]
Note: sometimes, it takes three dashes and not two, especially when the CLI follows strictly the Gnu options styles:
The Gnu style command line options provide support for option words (or keywords), yet still maintain compatibility with the Unix style options.
The options in this style are sometimes referred to aslong_options
and the Unix style options asshort_options
.
The compatibility is maintained by preceding the long_options with two dashes
Similar to the Unix style double-hyphen ’<code>--
'、Gnu スタイルには 3 つのハイフン '<code>---' があり、オプションの解析が中止されることを通知し、残りのテキストを引数として扱います (つまり、コマンド ラインから文字どおりに読み取ります)。
したがって...「--
」では不十分な場合 (Git コマンドを使用する必要があります)、「---
」を試してください。
git branch -D -- --track
私は msysgit 1.7.0.2 を使用していますが、提案された解決策は機能しません:
git branch -D -- --track # は機能しません
エラーは報告されませんが、ブランチはまだ残っています。最終的に、次の方法でブランチを強制的に削除しました。
rm .git/refs/heads/--トラック
二重ハイフンは、二重引用符とアンパサンドを含むブランチ名を持つリモートでは機能しませんでした。ただし、名前の引用符をラップし、含まれている引用符をエスケープするとうまくいきました。
git push origin --delete "123-my-branch-&-some\"quoted-text\""
そしてローカル:
git branch -D "123-my-branch-&-some\"quoted-text\""
好きなブランチを削除できるソフトウェア:sourcetreeを使用できます。