Escaping in git add a leading “-” in the filename?











up vote
2
down vote

favorite












In git add how can you escape a leading "-" character in the filename? e.g.:



git add -index-apache-.html


gives:



error: unknown switch `d'


Thanks!



PS. same for



git checkout









share|improve this question


















  • 3




    Try git add -- -index-apache-.html. For more details, see this answer.
    – jubobs
    Sep 6 '14 at 18:39








  • 1




    @Jubobs, thanks, it works!
    – pebox11
    Sep 6 '14 at 18:46















up vote
2
down vote

favorite












In git add how can you escape a leading "-" character in the filename? e.g.:



git add -index-apache-.html


gives:



error: unknown switch `d'


Thanks!



PS. same for



git checkout









share|improve this question


















  • 3




    Try git add -- -index-apache-.html. For more details, see this answer.
    – jubobs
    Sep 6 '14 at 18:39








  • 1




    @Jubobs, thanks, it works!
    – pebox11
    Sep 6 '14 at 18:46













up vote
2
down vote

favorite









up vote
2
down vote

favorite











In git add how can you escape a leading "-" character in the filename? e.g.:



git add -index-apache-.html


gives:



error: unknown switch `d'


Thanks!



PS. same for



git checkout









share|improve this question













In git add how can you escape a leading "-" character in the filename? e.g.:



git add -index-apache-.html


gives:



error: unknown switch `d'


Thanks!



PS. same for



git checkout






git






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 6 '14 at 18:36









pebox11

502623




502623








  • 3




    Try git add -- -index-apache-.html. For more details, see this answer.
    – jubobs
    Sep 6 '14 at 18:39








  • 1




    @Jubobs, thanks, it works!
    – pebox11
    Sep 6 '14 at 18:46














  • 3




    Try git add -- -index-apache-.html. For more details, see this answer.
    – jubobs
    Sep 6 '14 at 18:39








  • 1




    @Jubobs, thanks, it works!
    – pebox11
    Sep 6 '14 at 18:46








3




3




Try git add -- -index-apache-.html. For more details, see this answer.
– jubobs
Sep 6 '14 at 18:39






Try git add -- -index-apache-.html. For more details, see this answer.
– jubobs
Sep 6 '14 at 18:39






1




1




@Jubobs, thanks, it works!
– pebox11
Sep 6 '14 at 18:46




@Jubobs, thanks, it works!
– pebox11
Sep 6 '14 at 18:46












2 Answers
2






active

oldest

votes

















up vote
5
down vote



accepted










Use the -- to get around this issue. Anything past the double-dash is treated as just a filename.



This is more a Bash convention than a Git convention, as -- traditionally signifies the end of options.




A -- signals the end of options and disables further option processing. Any arguments after the -- are treated as filenames and arguments. An argument of - is equivalent to --.







share|improve this answer






























    up vote
    1
    down vote













    As an alternative to the general -- syntax,



    git add -- -index-apache-.html


    you could also use



    git add ./-index-apache-.html


    This works because the argument is a filename. Prepending ./ says "look for this file in the current directory", so it does not change the meaning of the filename (git would've looked there anyway), but it also means the argument no longer starts with - and cannot be confused with option switches.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25703528%2fescaping-in-git-add-a-leading-in-the-filename%23new-answer', 'question_page');
      }
      );

      Post as a guest
































      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      5
      down vote



      accepted










      Use the -- to get around this issue. Anything past the double-dash is treated as just a filename.



      This is more a Bash convention than a Git convention, as -- traditionally signifies the end of options.




      A -- signals the end of options and disables further option processing. Any arguments after the -- are treated as filenames and arguments. An argument of - is equivalent to --.







      share|improve this answer



























        up vote
        5
        down vote



        accepted










        Use the -- to get around this issue. Anything past the double-dash is treated as just a filename.



        This is more a Bash convention than a Git convention, as -- traditionally signifies the end of options.




        A -- signals the end of options and disables further option processing. Any arguments after the -- are treated as filenames and arguments. An argument of - is equivalent to --.







        share|improve this answer

























          up vote
          5
          down vote



          accepted







          up vote
          5
          down vote



          accepted






          Use the -- to get around this issue. Anything past the double-dash is treated as just a filename.



          This is more a Bash convention than a Git convention, as -- traditionally signifies the end of options.




          A -- signals the end of options and disables further option processing. Any arguments after the -- are treated as filenames and arguments. An argument of - is equivalent to --.







          share|improve this answer














          Use the -- to get around this issue. Anything past the double-dash is treated as just a filename.



          This is more a Bash convention than a Git convention, as -- traditionally signifies the end of options.




          A -- signals the end of options and disables further option processing. Any arguments after the -- are treated as filenames and arguments. An argument of - is equivalent to --.








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Sep 6 '14 at 18:46

























          answered Sep 6 '14 at 18:41









          Makoto

          78.9k15122164




          78.9k15122164
























              up vote
              1
              down vote













              As an alternative to the general -- syntax,



              git add -- -index-apache-.html


              you could also use



              git add ./-index-apache-.html


              This works because the argument is a filename. Prepending ./ says "look for this file in the current directory", so it does not change the meaning of the filename (git would've looked there anyway), but it also means the argument no longer starts with - and cannot be confused with option switches.






              share|improve this answer



























                up vote
                1
                down vote













                As an alternative to the general -- syntax,



                git add -- -index-apache-.html


                you could also use



                git add ./-index-apache-.html


                This works because the argument is a filename. Prepending ./ says "look for this file in the current directory", so it does not change the meaning of the filename (git would've looked there anyway), but it also means the argument no longer starts with - and cannot be confused with option switches.






                share|improve this answer

























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  As an alternative to the general -- syntax,



                  git add -- -index-apache-.html


                  you could also use



                  git add ./-index-apache-.html


                  This works because the argument is a filename. Prepending ./ says "look for this file in the current directory", so it does not change the meaning of the filename (git would've looked there anyway), but it also means the argument no longer starts with - and cannot be confused with option switches.






                  share|improve this answer














                  As an alternative to the general -- syntax,



                  git add -- -index-apache-.html


                  you could also use



                  git add ./-index-apache-.html


                  This works because the argument is a filename. Prepending ./ says "look for this file in the current directory", so it does not change the meaning of the filename (git would've looked there anyway), but it also means the argument no longer starts with - and cannot be confused with option switches.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited yesterday

























                  answered yesterday









                  melpomene

                  55.5k54387




                  55.5k54387






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25703528%2fescaping-in-git-add-a-leading-in-the-filename%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest




















































































                      Popular posts from this blog

                      Xamarin.iOS Cant Deploy on Iphone

                      Glorious Revolution

                      Dulmage-Mendelsohn matrix decomposition in Python