我在远程裸仓库 hub
中有一个名为 develop
的分支,我有一个 checkout 副本我本地 git 存储库中的 develop
分支(用户 poomalai
)。
我已经从另一个 checkout 副本(用户 raj
),并推送到 hub 存储库。
现在,当我将更改从集线器 pull 到(用户 poomalai
)时,它工作正常,并且我有提交消息 file deletion
在 git 日志中。
我已将文件添加到(用户 poomalai
)的 .gitignore
文件中。
现在,我已经在我的本地存储库(用户 poomalai
)中创建了该文件。
现在该文件不再在版本控制中,并且 git 不会跟踪对该文件的更改。
但是当我尝试切换到其他分支时,它会显示以下内容:
error: The following untracked working tree files would be overwritten by checkout:
Mydirectory/myfile.php
Please move or remove them before you can switch branches.
Aborting
当我使用 linux rm
命令删除文件时,我可以切换分支。
如果我再次创建该文件,它会再次抛出相同的错误。
我需要该文件位于目录中,但 git 不应跟踪它。
我尝试了以下命令:
git rm
fatal: pathspec 'diamonds_webservice/dbconnect.php' did not match any files
git gc
git reset --hard HEAD
git pull
没有任何作用。请有人帮助我
最佳答案
这是可能的,因为文件已添加到“目标分支”中的存储库。
确保文件是从“目标分支”git rm
编辑的,然后尝试切换分支。
作为@CharlesB据说,git 这样做是为了确保数据完整性,因此在切换目录时不会丢失任何内容。
关于git 在切换分支时说 "The following untracked working tree files would be overwritten by checkout",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6829671/