git 在切换分支时说 "The following untracked working tree files would be overwritten by checkout"

标签 git

我在远程裸仓库 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/

相关文章:

Git:无法撤消本地更改(错误:路径...未 merge )

带有电子邮件地址形式的用户名的 Git 远程 URL

git - .gitignore_global 不工作,甚至 .gitconfig 显示 .gitignore_global

git - 是否可以构建 `git`,使安装目录和部署前缀不相同?

git - 如何重用 docker-compose 项目?

python - pip 连接失败 : cannot fetch index base URL http://pypi. python.org/simple/

git - git 如何知道要在哪个提交处检查子模块?

XCode 推送到 AWS CodeCommit -> 发生未知错误

javascript - 包括来自 raw.github.com 的 js

git - 创建一个包含另一个 git 存储库的 git 存储库