在 Mac 上工作时,我的 IDE 生成了一个包含 :
(冒号)字符的目录,该目录被推送到 git 存储库。当我稍后切换到我的 PC 上工作时,我发现我无法 pull 目录,收到一个 fatal: cannot create directory at... invalid argument
错误。
如何删除或重命名不可 pull 目录?
我正在使用 GitHub.com,所以使用网站界面的解决方案也是可以接受的。
最佳答案
你需要记住 git pull
实际上是一个两步过程。首先它使用 fetch
来检索远程文件。然后它将尝试执行 fast-forward
merge
以直接在您的工作之上应用更改。
所以在远程使用fetch
。这将确保您在 git 存储库中设置了远程更改。我会说从 git repo 运行以下命令:
ls | xargs -I'{}' git checkout -- '{}'
但是你说你在 Windows 机器上,所以你可能只需要循环并手动执行。此外,这还假设您的存储库的根目录中没有创建新文件。
现在,如果您真的想恢复目录的创建,请执行以下操作(假设远程为 origin
,分支为 master
)。
git update-ref refs/heads/master $(git rev-parse origin/master)
git add --all .
# amend the commit to remove the folder from history
# only do this if you can rebase the remote w/o repercussion
git commit --amend
# otherwise just add a new commit on top of the old
git commit
现在查看日志,看看是否一切正常,如果正常,则推送到远程(如果您使用了 --amend
,那么您将不得不强制推送)。
关于git - 删除无法 pull 到 PC 的 Git 存储库上的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15490494/