Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a file named "--" to a git repository

Tags:

git

I have created a file a gave it the name --. How can I add it to the git repository?

$ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        --

nothing added to commit but untracked files present (use "git add" to track)

I know that I could do git add ., but I don't want to. I want to know how to specifically add this file, named --.

I tried:

$ git add --
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?
$ git add "--"
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?
$ git add '"--"'
fatal: pathspec '"--"' did not match any files
$ git add \-\-
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?

So, how to add a file named -- to prepare it for commit?

like image 566
Ionică Bizău Avatar asked Dec 02 '25 23:12

Ionică Bizău


1 Answers

You can use:

git add ./--

or:

git add $PWD/--

or even:

git add -- --

These are all standard techniques for dealing with inappropriately named files that look like options to a command but are actually files. The standard requirement for these tricks is for rm -f ./-- or mv ./-- ./something-meaningful.

You are strongly counselled against creating a file with the name -- ever.

It is a name with a standard meaning for Unix commands generally, based on a mandate from POSIX. Many commands use it to mark the end of the options and indicate that the 'file name' (non-option) parameters follow after the -- argument.

So almost every time you need to do something with the file, you are going to have to treat its name specially. It isn't worth it. Anybody trying to work with you on your repository is going to hate you for it. You can't even edit it: vim -- doesn't edit the file --! OK; there are ways to edit it, such as vim ./-- and vim -- --, but this is obnoxious. (You can't cat the file; you can't use less or more on the file; you can't cp or mv the file; you can't list the file with ls -l --, ...)

like image 200
Jonathan Leffler Avatar answered Dec 04 '25 18:12

Jonathan Leffler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!