Reputation: 651
Whenever I try to add a file with whitespace in its name to git, it shows an Error as
"fatal: pathspec 'Tic' did not match any files"
Since I was New to git and Linux based terminal I have no idea how to do it.
Upvotes: 3
Views: 4085
Reputation: 4114
To expand on @ergonaut's correct answer, just for the sake of clarity, this is actually neither a git nor a Linux issue. This is just a general requirement for command lines across the board.
On any command line, each word (or in this case, string of words) is evaluated separately as either a command or a parameter to a command. So, for example, git's add
command is expecting a single parameter to come immediately after it (a filename). In this case, the next word it sees is just "Tic". Since it's only looking for a single parameter, it stops evaluating anything else at that point and that's why it's complaining about not being able to find the "Tic" file. When the words are enclosed in quotes, the entire string is evaluated as a single parameter, therefore fixing the issue.
Always wrap filenames that contain spaces with quotes when using them on the command line. Or even better, avoid using spaces in filenames. :-)
Upvotes: 2
Reputation: 10146
Try:
git add Tic\ tac\ toe.c
\
is used to escape special characters, though this is more bash
related rather than git
specific.
Alternatively, you could put the name of the file in quotes.
git add "Tic tac toe.c"
Upvotes: 1
Reputation: 7057
You should be able to quote the filename (eg. "file name"), or use an escape sequence (eg. file\< space >name).
Upvotes: 3
Reputation: 736
Start writing the first word and then press "Tab" button to use autocomplete and you will be happy ))
Upvotes: 0