8

我遇到了一个 git 问题,我想将分支合并到 master 但它拒绝合并,因为它认为我对文件进行了本地更改。执行状态显示没有任何更改,并且对文件进行差异化不会产生任何结果。这是终端输出:

$ git checkout ProductsAndContents
Switched to branch 'ProductsAndContents'

$ git status
# On branch ProductsAndContents
nothing to commit (working directory clean)

$ git checkout master
Switched to branch 'master'

$ git status
# On branch master
nothing to commit (working directory clean)

$ git merge ProductsAndContents
error: Your local changes to the following files would be overwritten by merge:
    tests/unit/src/models/BrandTests.js
Please, commit your changes or stash them before you can merge.
Aborting

任何帮助或建议将不胜感激!

4

4 回答 4

3

感谢 Andrew Myers 对我最初的问题的评论,我发现core.trustctimefalse解决问题的设置。

git config core.trustctime false

关于 inode 更改时间不匹配的问题。我猜这是因为 repo 位于与我正在使用的文件系统不同的机器上的文件共享上。

感谢所有的建议!

于 2013-03-04T15:05:43.890 回答
1

好吧,如果您确信自己不会丢失任何工作,请尝试以下操作:

rm tests/unit/src/models/BrandTests.js
git checkout -- tests/unit/src/models/BrandTests.js

这应该重置任何让它认为它发生变化的机制。如果它不起作用,请让其他可能的。

于 2013-03-01T20:27:08.670 回答
1

我猜这是你的场景:

$ git checkout ProductsAndContents
Switched to branch 'ProductsAndContents'

分支ProductsAndContents包含文件tests/unit/src/models/BrandTests.js,因此上面checkout创建它和/或确保它与请求的特定提交是最新的。

$ git status
# On branch ProductsAndContents
nothing to commit (working directory clean)

您没有进行任何更改,并从一个干净的工作目录开始,所以这很好。

$ git checkout master
Switched to branch 'master'

这确保了最新提交中包含的所有文件在master工作目录中都是最新的。但是,它不会删除或更新不包含在master中或被忽略的文件。在这里,无论出于何种原因,我假设master当前不包含有问题的文件。

$ git status
# On branch master
nothing to commit (working directory clean)

同样,您没有进行任何修改。此处未将相关文件作为未跟踪文件提及这一事实可能意味着它被忽略(在.gitignore或 中.git/info/exclude)。master不包含该文件,因此它不关心它是否存在。

$ git merge ProductsAndContents
error: Your local changes to the following files would be overwritten by merge:
    tests/unit/src/models/BrandTests.js
Please, commit your changes or stash them before you can merge.
Aborting

在这里,您在另一个分支中合并的尝试想要引入一个master当前没有的文件,这通常很好。但是,该文件存在于您的工作目录中,并且git不想丢弃不确定是否保留在存储库中的内容。正如其他地方所建议的那样,您可以(假设您知道它是安全的)只需删除该文件并重新尝试合并。

根据您提供的信息,我不能 100% 确定这就是您所拥有的;但是,您可以运行这两个命令来检查该情况:

git ls-files master -- tests/unit/src/models/BrandTests.js
git ls-files ProductsAndContents -- tests/unit/src/models/BrandTests.js

如果我的猜测是正确的,第一个命令不会显示文件存在,而第二个会。然后检查.gitignore.git/info/exclude是否被忽略(对于.gitignore,您可能需要检查两个分支中每个分支上存在的版本)。

于 2013-03-01T22:37:12.087 回答
-2

仅仅因为每个分支都没有要提交的内容并不意味着它们是相同的。我有兴趣使用查看两个文件之间的差异

git diff

您可以使用

git checkout -- tests/unit/src/models/BrandTests.js
于 2013-03-01T18:23:07.373 回答