Git pull if folder in remote contains spaces

Viewed 2271

I just want get pull of remote, but I can not do it correctly, because in remote repo appeared folder with space in name. Then after git pull I recieve message for all files in this folder, that git can't create it , and all this files put in unstaged changes as "deleted". enter image description here

After pull this situation:

$ git status
    On branch develop
    Your branch is up-to-date with 'origin/develop'.
    Changes not staged for commit:
      (use "git add/rm <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    ../support/UIKit/Layouts/Product /ProductBodyLayout.swift
               (and other files)

no changes added to commit (use "git add" and/or "git commit -a")

I know root of this problem - command line, which use git (MINGW32), interprets space like delimiter, so that this does not happen, on Windows, we should use space in path with \. But I don't understand, what should I do exactly in the moment, that done git pull operation without any deleted files? I need remove this files out deleted, but I can't do checkout on any of this files, and git add moves files to staged.

If I try git add:

$ git add ../support/UIKit/Layouts/Product\ /ProductBodyLayout.swift

It add "deleted" file to staged:

 $ git status
On branch develop
Your branch is up-to-date with 'origin/develop'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        deleted:    ../support/UIKit/Layouts/Product /ProductBodyLayout.swift

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    ../support/UIKit/Layouts/Product /ProductButtonLayout.swift
        (and other files)

If I try checkout I recieve an error:

 $ git checkout -- ../support/UIKit/Layouts/Product\ /ProductBodyLayout.swift
error: unable to create file support/UIKit/Layouts/Product /ProductBodyLayout.swift: No such file or directory
3 Answers

Putting double quotes around the full file path should work:

git add "../support/UIKit/Layouts/Product /ProductBodyLayout.swift"

You could also escape the space:

git add ../support/UIKit/Layouts/Product\ /ProductBodyLayout.swift

But, while this gets around the immediate problem, moving forward you might want to avoid using file/path names which have characters which must be escaped. This is because you will have to keep escaping like this.

If you want to discard the delete operation, then take the advice of the bash and use this:

git checkout -- "../support/UIKit/Layouts/Product /ProductBodyLayout.swift"

If you read the message from git carefully, it gives several suggestions. Probably the one you want is:

git checkout -- <file>...

Just be sure to put quotes around the file name. Then you can rename the file with git mv and git commit.

It seems as an issue with mingw of handling spaces. Stack overflow question on mingw handling of spaces.

You can use double quotes(") around the file name to handle this issue. Or copy the files manually and add them locally as new files and remove spaces, so that this issue does not occur. The problem is that all the history is gone for the file and treated as new file.

Related