错误:结帐将覆盖以下未跟踪的工作树文件

ran*_*mor 18 git git-pull git-status

当我这样做git status时说nothing to commit, working directory clean

然后我这样做git pull --rebase,它说:

First, rewinding head to replay your work on top of it...
error: The following untracked working tree files would be overwritten by checkout:
    includes/resources/moduledata/12/_Fr4_02_Invention_IPA_SR_la-Fe?te.pdf
Please move or remove them before you can switch branches.
Aborting
could not detach HEAD
Run Code Online (Sandbox Code Playgroud)

做的时候类似的错误 git pull origin master

 * branch            master     -> FETCH_HEAD
error: The following untracked working tree files would be overwritten by merge:
    includes/resources/moduledata/12/_Fr4_02_Invention_IPA_SR_la-Fe?te.pdf
Please move or remove them before you can merge.
Aborting
Run Code Online (Sandbox Code Playgroud)

我的.gitignore档案:

? cat .gitignore 
.htaccess
bower_components/
Run Code Online (Sandbox Code Playgroud)

这个文件一直在出现,当我从文件系统中删除它时,git会说我删除了这个文件,而在其他消息中,它说它没有跟踪.怎么可能同时没有跟踪和跟踪?

Mik*_*all 30

由于文件名的大小写更改,也可能发生这种情况.我遇到了同样的问题,这就是为我解决的问题.

git config core.ignorecase true
Run Code Online (Sandbox Code Playgroud)

适用于Mac或PC.

替代解决方案: 以下未跟踪的工作树文件将被结帐覆盖


jub*_*0bs 15

如果没有完整的回购图片,接下来的内容更多的是猜测,而不是其他任何东西,但它可以解释这种情况.假设您的历史记录如下:

A -- C [origin/master]
  \ 
   B [HEAD, master]
Run Code Online (Sandbox Code Playgroud)

你写:

这个文件一直在出现,当我从文件系统中删除它时,git会说我删除了这个文件,而在其他消息中,它说它没有跟踪.

我猜你可能已经跑了

git rm --cached <file-in-question>
Run Code Online (Sandbox Code Playgroud)

并在提交中承诺删除B; 因此,不再在您的本地仓库中跟踪该文件,但它仍然存在于您的工作树中.

与此同时,上游分支收到提交C您的合作者之一,它<file-in-question>不是从版本控制中删除.你试图用什么来影响

git pull --rebase
Run Code Online (Sandbox Code Playgroud)

是这样的:

 A -- C [origin/master]
       \ 
        B' [HEAD, master]
Run Code Online (Sandbox Code Playgroud)

但是,正如消息所说,

[...]未跟踪的工作树[文件]将被结帐覆盖

实际上,倒带提交C(为了在其上重放B)将导致在工作树中检出<file-in-question>(来自提交C)的修订,其中已存在同名的未跟踪文件.该未跟踪文件的内容可能很有价值; 您可能不希望该文件被其他版本覆盖.因此,Git停在它的轨道上并告诉你什么是错的.

编辑:这是一个重现情况的婴儿示例......

cd ~/Desktop
mkdir test
cd test
git init
touch README.md
git add README.md
git commit -m "add README"

# simulate a remote branch moving ahead by one commit
# (that doesn't remove the README)
git checkout -b origin_master
printf "This is a README.\n" > README.md
git add README.md
git commit -m "add description in README"

# remove the README and create a new commit on master
git checkout master
git rm --cached README.md
git commit -m "remove README"

# simulate an attempt to rebase master to its "upstream" branch, origin_master
git rebase --onto origin_master master
Run Code Online (Sandbox Code Playgroud)

最后一个命令吐出以下内容:

First, rewinding head to replay your work on top of it...
error: The following untracked working tree files would be overwritten by checkout:
    README.md
Please move or remove them before you can switch branches.
Aborting
could not detach HEAD
Run Code Online (Sandbox Code Playgroud)

我建议你跑

git fetch
git log --stat origin/master..master -- <file-in-question>
Run Code Online (Sandbox Code Playgroud)

检查是否发生了类似的事情.


Abh*_*oel 6

删除所有未跟踪的文件(仔细):

git clean  -d  -fx ""
Run Code Online (Sandbox Code Playgroud)