0

I have been and made a file called "-_todo.txt" in my git folder which I have been happily using since to keep a list of my todos. Now I'd like to rename it something more sensible e.g. "todo.txt". I understood you should use "git mv" to do so. However

git mv -_todo.txt todo.txt

gives me an error: unknown switch. Trying out for the sake of trying

git mv "-_todo.txt" todo.txt

gave the same error.

Searching the internet the last 30 minutes with my favorite search engine didnt help me find anything useful ("git mv filename with underscore"). The official docs on "git mv" didnt help either.

How to rename such a file?

Note on duplication:

Although I agree - in hindsight - this question has been answered elsewhere, the associated title of that question is arguably a bit cryptic/hard to find if searching for something like "git mv filename with underscore [in it]". Maybe improve the title/search-ability of that question/answer? - maybe Im being a hassle.

balletpiraat
  • 206
  • 1
  • 11
  • 1
    test it with `./-_todo.txt` – Mohammad Ali Nov 10 '18 at 10:53
  • It definitely boils down to the same problem. Thanks @HostileFork – balletpiraat Nov 10 '18 at 11:06
  • 1
    *"Maybe improve the title/search-ability of that question/answer? - maybe Im being a hassle."* -> This is actually why duplicates are not considered a bad thing. Duplicates offer more wording entry points for the search engine to find. FWIW, I found it by searching on how to "escape" dashes because that is the more precise general terminology...and so the other question's title makes sense to me (and probably others). – HostileFork says dont trust SE Nov 10 '18 at 11:24
  • I see, because the normal meaning of the dash (specifying optional arguments) has to be "escaped from" you call the '--' an escape character, right? Thanks for the additional information. – balletpiraat Nov 10 '18 at 11:31
  • @balletpiraat "Escaping" is like what you do with backslashes, such as when you want to do `"a \"quoted string\" like this"` to get `a "quoted string" like this`. So I wondered if there was something like that for the dash. It appears not, so you've found other options. But I still would think of it as "looking for an escaping mechanism"...that's where I'd start my search if I had this problem. – HostileFork says dont trust SE Nov 10 '18 at 11:39

2 Answers2

3

You can use -- to separate between git's switches and the file names, so you won't even have to escape the - in the file name:

$  git mv -- -_todo.txt todo.txt
Mureinik
  • 297,002
  • 52
  • 306
  • 350
2

Since git tries to parse the - as a flag you have to use ./

# use the full path to avoid parse the prefix as parameter
git mv "./-_todo.txt" todo.txt

enter image description here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167