由于未跟踪的工作树文件而无法切换到其他分支

问题描述 投票:0回答:2

我已经创建了子模块,它应该是创建后来自其他 git Repo 的内容,当我尝试切换到另一个分支时,它似乎一切都很好,它给了我错误

> git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks checkout Feature/7-SOE_Update --progress
> error: The following untracked working tree files would be overwritten by checkout:
> Application_Layer/Appl_SOC/SOC_Algorithm/SOC_Basic.c
> Application_Layer/Appl_SOC/SOC_Algorithm/SOC_Basic.h
> Please move or remove them before you switch branches.
> Aborting``

我尝试使用 git status 来查看发生了什么 --给我最新的信息
我尝试在 .git 模块文件中使用ignore = dirty --仍然无法切换到其他分支 我试图强行切换 -- 删除了我未跟踪的文件

这是唯一对我有用的解决方案 git 子模块 deinit --all git拉 rm -rf 构建 rm -rf $RETDEC_INSTALL_DIR 但是当我切换回分支并尝试再次切换到其他分支时,问题再次返回,每次切换到此分支时重复此操作没有任何意义。

还在这个子模块中,只有三个文件具有未跟踪状态,但其他文件都很好,没有抱怨它们,我认为这根本没有意义,我的意思是它应该抱怨所有文件,对吗?

git github gitlab atlassian-sourcetree
2个回答
1
投票

Git 尝试签出当前分支中未跟踪的相同文件。这些文件可能是由于未完成的合并等而留下的。Git 甚至为您提供了一个秘诀:

Please move or remove them before you switch branches.

您可以

git clean
然后尝试再次结帐。确保您没有在这些文件中放入任何您需要的工作。

git clean
可以给你

fatal: clean.requireForce defaults to true and neither -i, -n, nor -f given; refusing to clean

只需重复

git clean -f

如果您不确定是否要删除所有未跟踪的文件,您可以进行交互:

git clean -i
Would remove the following item:
  ufff
*** Commands ***
    1: clean                2: filter by pattern    3: select by numbers
    4: ask each             5: quit                 6: help
What now> 

或者您可以干运行它以查看哪些文件将被删除,并查看您不会删除任何需要保留的文件:

git clean -n
Would remove ufff

https://git-scm.com/docs/git-clean


0
投票

我做了 git reset --hard ,然后 git clean ,然后 git clean -f 。我能够切换到我的功能分支。是的,我确实丢失了我很好的更改,我已经恢复了

© www.soinside.com 2019 - 2024. All rights reserved.