我只想获取远程消息,但是我做不正确,因为在远程仓库中出现了名称中带有空格的文件夹。然后,在git pull之后,我收到该文件夹中所有文件的消息,该git无法创建它,并且所有这些文件都以“已删除”的形式进行了未分段的更改。
出现这种情况后:
$ 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")
我知道这个问题的根源-使用git(MINGW32)的命令行解释空格,就像定界符一样,这样就不会发生,在Windows上,我们应该在路径\
中使用空格。但我不明白,此刻我该怎么办,
做了git pull操作而没有任何删除的文件?我需要将这些文件删除,但不能对其中任何文件进行检出,git add
会将文件移至暂存状态。
如果我尝试git add:
$ git add ../support/UIKit/Layouts/Product\ /ProductBodyLayout.swift
它将“已删除”文件添加到暂存中:
$ 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)
如果我尝试结帐,则会收到错误消息:
$ git checkout -- ../support/UIKit/Layouts/Product\ /ProductBodyLayout.swift
error: unable to create file support/UIKit/Layouts/Product /ProductBodyLayout.swift: No such file or directory
答案 0 :(得分:0)
在完整文件路径周围加上双引号应该可以工作:
git add "../support/UIKit/Layouts/Product /ProductBodyLayout.swift"
您还可以逃脱空格:
git add ../support/UIKit/Layouts/Product\ /ProductBodyLayout.swift
但是,尽管这解决了紧迫的问题,但继续前进可能要避免使用具有必须转义的字符的文件/路径名。这是因为您将不得不继续这样逃避。
如果要放弃删除操作,请听bash的建议并使用它:
git checkout -- "../support/UIKit/Layouts/Product /ProductBodyLayout.swift"
答案 1 :(得分:0)
如果您仔细阅读git
中的消息,它会提供一些建议。您可能想要的是:
git checkout -- <file>...
请务必在文件名两边加上引号。然后,您可以使用git mv
和git commit
重命名文件。
答案 2 :(得分:0)
这似乎与处理空间的问题有关。 Stack overflow question on mingw handling of spaces。
您可以在文件名前后使用双引号(“)来解决此问题。或者手动复制文件,然后将其本地添加为新文件并删除空格,这样就不会发生此问题。问题在于所有文件的历史记录消失了,并被视为新文件。