git说:“以下未跟踪的工作树文件将被checkout覆盖”切换分支时 [英] git says "The following untracked working tree files would be overwritten by checkout" when switching branches

查看:1214
本文介绍了git说:“以下未跟踪的工作树文件将被checkout覆盖”切换分支时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在远程裸回购 hub 中有一个名为开发的分支,我在本地git存储库中拥有develop分支的结帐副本(用户<强> poomalai )。
我从另一个签出副本(用户 raj )删除了(git rm --cached)文件(Mydirectory / myfile.php)并将其推送到中心存储库。



现在,当我将更改从集线器拉到poomalai时,它工作正常,我在git日志中收到了删除文件的提交消息。我在用户poomalai的.gitignore文件中添加了该文件。现在我已经在我的本地仓库(用户poomalai)中创建了这个文件。



现在该文件不再在版本控制中,并且git没有跟踪文件的更改。

但是当我尝试将分支切换到其他分支时,它会显示以下内容:

 错误:以下未跟踪的工作树文件将被checkout覆盖:
Mydirectory / myfile.php
请在移动或删除它们,然后才能切换分支。
正在取消

当我使用linux rm命令删除文件时,我可以切换分支。如果我再次创建该文件,它将再次引发相同的错误。我需要该文件在目录中,但不应该被git跟踪。



我试过以下命令:

  git rm ---->说致命:pathspec'diamonds_webservice / dbconnect.php'不匹配任何文件

git gc
git reset --hard HEAD
git pull

没有用。请有人帮助我

解决方案

这可能是因为该文件被添加到目标分支中的回购,确保该文件是从'目标分支'git rm'ed,然后尝试切换分支。

正如charles所说,git确保数据的完整性,所以切换目录时没有任何东西丢失。


I have a branch called "develop" in remote bare repo "hub" and I have a checkout copy of the develop branch in my local git repository (user poomalai). I have deleted (git rm --cached) a file (Mydirectory/myfile.php) from another checkout copy (user raj) and pushed to the hub repository.

Now when I pull the changes from the hub to "poomalai" it worked fine and I got the commit message of file deletion in the git log. I have added the file in the .gitignore file in the user poomalai. Now I have created the file in my local repo (user poomalai).

Now the file is no more in the version control and changes to the file is not tracked by git.

But when I try to switch the branch to some other, it says the following

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

When I remove the file using linux rm command, I am able to switch branches. If I create the file again, it again throws the same error. I need the file to be in the directory but it should not be tracked by git.

I tried following commands:

git rm ----> says fatal: pathspec 'diamonds_webservice/dbconnect.php' did not match any files

git gc
git reset --hard HEAD
git pull

Nothing works. Please someone help me

解决方案

This could be possible because the the file is added to the repo in the 'target branch', ensure that the file is git rm 'ed from the 'target branch', and then try switching branches.

As charles said, git does it to ensure data integrity, so that nothing is lost when switching directories.

这篇关于git说:“以下未跟踪的工作树文件将被checkout覆盖”切换分支时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆