2009-07-28 12 views
45

Ich weiß, das ist keine Programmierfrage, aber es ist mit Git verwandt. Ich habe aus Versehen eine Niederlassung in git --track genannt erstellt haben (habe ich die Reihenfolge der Optionen falsch, wenn ein Remote-Zweig verschmelzenden)Einen schlecht benannten Git-Zweig löschen

Der reguläre Befehl funktioniert nicht:

git branch -D "--track" 

Ich habe versucht, mit Anführungszeichen zu entkommen und umgekehrte Schrägstriche funktionieren jedoch nicht.

Irgendwelche Ideen?

+0

Ich würde gerne wissen, wie Sie diesen Zweig in erster Linie erstellt haben. Es sieht nicht so aus als hättest du "git branch - --track". Oder hast du? –

+3

Hier ist die problematische Linie, ich habe versucht, eine entfernte Niederlassung zu verfolgen. git branch -b --track Herkunft/dev – Felix

+0

Zitate oder Schrägstriche funktionieren nicht, weil sie früher von Ihrer Shell interpretiert werden, während das Problem in Git und seinem Argument liegt. – Kos

Antwort

79

Haben Sie versucht,

git branch -D -- --track 

? die "--" ist in der Regel die Konvention für "was keine Option folgt, ist, was auch immer der Name"


Von "The Art of Unix Programming", Abschnitt "Command-Line Options":

It is also conventional to recognize a double hyphen as a signal to stop option interpretation and treat all following arguments literally.

Sie diese Konvention finden in anderen (nicht notwendig, Unix-ähnlichen) CLI (Command Line Interface) wie cleartool:

If a nonoption argument begins with a hyphen () 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- 

Der P18 (ein schneller und flexible Datei-Präprozessor mit Makro-Verarbeitungsfunktionen und spezieller Unterstützung für die Internationalisierung) erwähnt, dass auch und gibt eine gute Beschreibung der allgemeinen Idee hinter dieser Konvention:

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.

Das OptionParser Werkzeug geschrieben in Rubin legt es auch ganz deutlich aus: *

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"] 

Hinweis: Manchmal dauert es drei Striche und nicht zwei, vor allem, wenn die CLI folgt streng den Gnu Optionen Stile:

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 as long_options and the Unix style options as short_options.
The compatibility is maintained by preceding the long_options with two dashes

Similar to the Unix style double-hyphen ’ -- ’, the Gnu style has a triple-hyphen ’ --- ’ to signal that option parsing be halted and to treat the remaining text as arguments (that is, read literally from the command line)

Also ... wenn '--' ist nicht genug (es sollte mit Git-Befehle sein), versuchen '---'

+1

Ist - eine Konvention nur für Git oder für die meisten Linux-Kommandozeilen-Tools? – ZelluX

+0

@Zelux: gute Frage. Ich habe das nur überprüft. Nicht für jetzt bestätigt. – VonC

+0

Vielleicht nicht alle, aber sicherlich für solche Grundlagen wie rm. Es ist eine Möglichkeit, wie Sie eine Datei namens "-rf" loswerden .... – quark

7
git branch -D -- --track 
4

Ich verwende msysgit 1.7.0.2 und die vorgeschlagene Lösung funktioniert nicht:

git branch -D - --track # nicht

funktioniert wird kein Fehler gemeldet, aber der Zweig noch bleibt . Ich landete mit Gewalt den Zweig über das Entfernen bis:

rm.git/refs/heads/- track

1

Der doppelte Bindestrich funktionierte nicht für mich auf Remote mit einem Zweignamen, der doppelte Anführungszeichen und Et-Zeichen enthält. Allerdings Umwickeln der Name Zitate und entkommen die darin enthaltenen Zitate hat seinen Zweck erfüllt:

git push origin --delete "123-my-branch-&-some\"quoted-text\"" 

und lokal:

git branch -D "123-my-branch-&-some\"quoted-text\"" 
0

Ich hatte ein ähnliches Problem, wo ich zufällig mit einem „r“ Zweig endete. Ich kann nicht herausfinden, wie es entfernen mit git Befehlen, damit ich es nur im .git Ordner entfernen:

$ cd .git/refs/head $ ls *r -r $ rm "*r"

Diese Lösung nur sicher war, weil es der einzige Zweig wurde aufgelistet, die in „r beendet "aber es hat das Problem gelöst ...

0

können Sie Software mamed sourcetree verwenden, die jede Branche löschen können, die Sie mögen.

Verwandte Themen