在我的分支上,我在.gitignore中有一些文件

在另一个分支上,这些文件不是。

我想将不同的分支合并到我的分支中,我不关心这些文件是否不再被忽略。

不幸的是,我得到了这个:

以下未跟踪的工作树文件将被合并覆盖

我如何修改我的pull命令来覆盖这些文件,而不需要我自己找到、移动或删除这些文件?


当前回答

对于那些不知道的人,git忽略了文件和文件夹中的大写/小写名称差异。当您用不同的情况将它们重命名为完全相同的名称时,结果是一场噩梦。

当我将文件夹从“Petstore”重命名为“Petstore”(大写到小写)时遇到了这个问题。我已经编辑了我的.git/config文件以停止忽略大小写,进行了更改,压缩了我的提交,并保存了我的更改以移动到不同的分支。我不能将我所存储的更改应用到另一个分支。

The fix that I found that worked was to temporarily edit my .git/config file to temporarily ignore case again. This caused git stash apply to succeed. Then, I changed ignoreCase back to false. I then added everything except for the new files in the petstore folder which git oddly claimed were deleted, for whatever reason. I committed my changes, then ran git reset --hard HEAD to get rid of those untracked new files. My commit appeared exactly as expected: the files in the folder were renamed.

我希望这能帮助你避免我同样的噩梦。

其他回答

您可以试试这个命令

git clean -df

编辑: 请注意,这将删除可能有价值的未跟踪文件。 感谢@zhekaus

清洁/重置/硬签出/重基都不适合我。

所以我只是删除了git抱怨的文件*

rm /path/to/files/that/git/complained/about

*我检查了这个文件是否可以通过在一个单独的文件夹中签出一个全新的回购来删除(文件不在那里)

如果这是一次性操作,那么在执行拉取操作之前,可以从工作目录中删除所有未跟踪的文件。阅读如何从当前Git工作树中删除本地(未跟踪)文件?有关如何删除所有未跟踪的文件的信息。

请确保不要意外删除未跟踪的文件,你仍然需要;)

对于那些不知道的人,git忽略了文件和文件夹中的大写/小写名称差异。当您用不同的情况将它们重命名为完全相同的名称时,结果是一场噩梦。

当我将文件夹从“Petstore”重命名为“Petstore”(大写到小写)时遇到了这个问题。我已经编辑了我的.git/config文件以停止忽略大小写,进行了更改,压缩了我的提交,并保存了我的更改以移动到不同的分支。我不能将我所存储的更改应用到另一个分支。

The fix that I found that worked was to temporarily edit my .git/config file to temporarily ignore case again. This caused git stash apply to succeed. Then, I changed ignoreCase back to false. I then added everything except for the new files in the petstore folder which git oddly claimed were deleted, for whatever reason. I committed my changes, then ran git reset --hard HEAD to get rid of those untracked new files. My commit appeared exactly as expected: the files in the folder were renamed.

我希望这能帮助你避免我同样的噩梦。

问题是,当我们有传入的更改,将合并未跟踪的文件,git抱怨。这些命令帮助了我:

git clean -dxf
git pull origin master