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

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

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

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

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

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


当前回答

唯一对我有用的命令是: (请注意,这会删除所有本地文件)

git fetch --all
git reset --hard origin/{{your branch name}}

其他回答

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

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

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

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

唯一对我有用的命令是: (请注意,这会删除所有本地文件)

git fetch --all
git reset --hard origin/{{your branch name}}

如果你考虑使用-f标志,你可以先运行它作为一个演练。你只需要提前知道你接下来会遇到什么样有趣的情况;-P

-n 
--dry-run 
    Don’t actually remove anything, just show what would be done.

对于那些不知道的人,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 add -A
git stash
git pull

你可以使用git stash list这个命令检查你的本地存储文件