2009-07-28 6 views
45

Je sais que ce n'est pas strictement une question de programmation, mais elle est liée à git. J'ai accidentellement créé une branche dans git appelé --track (je suis arrivé l'ordre des options mal lors de la fusion d'une branche à distance)Supprimer une branche git mal nommée

La commande régulière ne fonctionne pas:

git branch -D "--track" 

J'ai essayé d'échapper avec des citations et des barres obliques inversées, mais aucun travail.

Des idées?

+0

Je voudrais savoir comment vous avez réussi à créer cette branche en premier lieu. Il ne semble pas que vous ayez "git branch - --track". Ou avez-vous? –

+3

Voici la ligne fautive, j'essayais de suivre une branche distante. git branche -b --track origin/dev – Felix

+0

Les citations ou les barres obliques ne fonctionnent pas car elles sont interprétées plus tôt, par votre shell, alors que le problème réside dans Git et son analyse syntaxique. – Kos

Répondre

79

Avez-vous essayé

git branch -D -- --track 

? le "--" est généralement la convention pour "ce qui suit est pas une option, quel que soit son nom"


De "The Art of Unix Programming", section "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.

Vous trouverez cette convention dans d'autres CLI (non Unix connexes nécessaires) (Command Line Interface) comme 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- 

Le P18 (un fichier rapide et flexible préprocesseur avec des capacités de traitement macro et un soutien particulier pour l'internationalisation) mentionne que aussi et donne une bonne description de l'idée générale derrière cette 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.

L'outil OptionParser écrit en rubis met également en très clairement: *

Option Parsing Fin

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: parfois, il faut trois tirets et non deux, en particulier lorsque le CLI suit strictement les choix Gnu 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 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)

Alors ... si '--' n'est pas suffisant (il devrait être avec les commandes Git), essayez '---'

+1

Is - une convention pour git seulement ou pour la plupart des outils de ligne de commande linux? – ZelluX

+0

@Zelux: bonne question. Je vérifiais juste ça. Pas confirmé pour le moment. – VonC

+0

Peut-être pas tout, mais certainement pour des bases telles que RM. C'est une façon de se débarrasser d'un fichier appelé "-rf" .... – quark

7
git branch -D -- --track 
4

J'utilise msysgit 1.7.0.2 et la solution proposée ne fonctionne pas:

git branch -D - --track # ne fonctionne pas

Aucune erreur est signalée, mais la branche reste encore . J'ai fini par enlever de force la branche via:

rm.git/refs/heads/- track

1

Le double trait d'union ne fonctionnait pas pour moi à distance avec un nom de branche contenant des guillemets doubles et des esperluettes. emballage Cependant, les citations de nom et échapper aux citations contenues ont fait le travail:

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

et localement:

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

J'ai eu un problème similaire où je accidentellement fini avec une branche « -r ». Je ne pouvais pas comprendre comment l'enlever à l'aide des commandes git donc je supprimer simplement dans le dossier .git:

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

Cette solution était sûre que parce qu'elle était la seule branche qui a pris fin dans la liste « r "mais il a résolu le problème ...

0

vous pouvez utiliser le logiciel mc sourcetree qui peut supprimer n'importe quelle branche que vous aimez.