2013-03-01 150 views
7

我有一个git问题,我想将分支合并到主服务器中,但拒绝合并,因为它认为我对文件进行了本地更改。执行状态显示没有变化,并且区分文件不会产生任何结果。这里的终端输出:Git拒绝合并,因为对未更改文件的更改

$ 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 

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

+1

你有没有设法将该文件放在'.git/info/exclude'文件或'.gitignore'文件中? – 2013-03-01 19:18:36

+2

[此答案](http://stackoverflow.com/a/12167041/166732)中的配置选项有帮助吗? – asm 2013-03-01 19:20:13

+0

嗨安德鲁,设置'core.trustctime'为false似乎已经做到了。感谢您指点我正确的方向:) – 2013-03-04 15:03:11

回答

3

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

git config core.trustctime false 

关于inode更改时间不匹配的问题。我猜这是因为回购站位于具有与我使用的文件系统不同的文件系统的计算机上的文件共享。

感谢您的所有建议!

-2

只因为每个分支都没有提交并不意味着它们是相同的。我有兴趣使用

git diff 

可以恢复使用

git checkout -- tests/unit/src/models/BrandTests.js 
+3

'请提交您的更改或隐藏它们,然后才能合并.'暗示未提交的更改,不支持分支之间的差异 – 2013-03-01 19:18:17

+0

确实没有更改提交,并且没有未跟踪的文件。正如我所提到的,差异产生零输出。我很困惑。 – 2013-03-04 12:55:38

1

好已致力于为回购修订查看这两个文件之间的差异,如果你有信心,你赢了请勿尝试以下任何方式:

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

这应该重置任何使其认为已发生更改的机制。如果它不起作用,那么可以有其他人。

+0

感谢Trev的建议!我尝试过,但不幸的是它仍然给出了同样的错误。所以很奇怪...... – 2013-03-04 12:54:18

+0

我也遇到过这个问题,但是看起来'git stash'会拒绝看到修改过的文件。我手动将其备份,检查出来并手动比较变化。有一个更好的方法... – 2014-06-02 15:37:50

+0

@PaulLammertsma不要忘记,一个'存储'只不过是另一个提交,并有自己的散列。您可以像对待其他任何提交一样对其进行操作。这留下了许多其他选择。我刚刚发现以上是最快的。 – 2014-06-02 22:20:43

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,您可能需要检查两个分支上每个分支上存在的版本)。

+0

谢谢!不幸的是,该文件在两个分支中,而不是在.gitignore或.git/info/exclude中。这里的输出: $ git ls-files master - tests/unit/src/models/BrandTests.js tests/unit/src/models/BrandTests.js $ git ls-files ProductsAndContents - tests/unit/src/models/BrandTests.js tests/unit/src/models/BrandTests.js – 2013-03-04 13:01:54