Git add folder with spaces in name

Problem

When I want to add something to the staging area, I usually type git add <folder name>. However, I cannot add folders with spaces in the name. My git add autoload does not allow spaces to be avoided.

for instance

I have a folder named: Folder A

I run the git add F < tab-autocomplete > , which becomes git add Folder A/ . If I try to add this folder, it will give an error:

fatal: pathspec 'Folder' did not match any files

This is because the correct syntax must be git add Folder\ A/ .

Summary

I am not sure how to fix this, and I cannot find any resources with a permanent fix. This problem How git treats folder names with spaces "describes the fix. But this is due to putting voice tags around the folder name, which I really don't want to do. Is there a better solution?

I am using git version 2.2.0 and zsh version 5.0.7. Thank you in advance!

+5
source share
2 answers

The solution is to wrap the folder name inside 'and' (single quotes).
In your example, try the following:

 git add 'Folder A' 

Hope this helps :)

+11
source

You are checking to see if the setting specified at the end of git with zsh: filenames with spaces "is set:

The shell backslash, as expected, escapes file names when I use the completion tab to insert a file name.

 % echo "testing" >> test<tab> 

Autofill after pressing the tab three times.

 % echo "testing" >> test\ four\ -\ latest.txt 

In other words, there must not be quptes ( " ) for proper completion, but spaces must be avoided.

-1
source

Source: https://habr.com/ru/post/1208712/


All Articles