Git P4 提交失败

6
我尝试在已经作为git和perforce之间中转桥的仓库上运行git p4 submit。多人将该仓库用作远程,并定期提交回perforce,这一切都一直运行良好,除了一些我无法复制的重复perforce提交的异常行为。然后某天突然出现错误,我无法再将任何git提交推送到perforce。
user@hostname:~/Source/code$ git p4 submit -M --export-labels
Perforce checkout for depot path //depot/perforce/workspace/ located at /home/user/Source/git-p4-area/perforce/workspace/
Synchronizing p4 checkout...
... - file(s) up-to-date.
Applying ffa390f comments in config xml files
//depot/perforce/workspace/sub/folder/structure/first.xml#3 - opened for edit
//depot/perforce/workspace/sub/folder/structure/second.xml#3 - opened for edit
//depot/perforce/workspace/sub/folder/structure/third.xml#3 - opened for edit
//depot/perforce/workspace/sub/folder/structure/forth.xml#3 - opened for edit
//depot/perforce/workspace/sub/folder/structure/fifth.xml#1 - opened for edit
error: patch failed: sub/folder/structure/first.xml:1
error: sub/folder/structure/first.xml: patch does not apply
error: patch failed: sub/folder/structure/second.xml:1
error: sub/folder/structure/second.xml: patch does not apply
error: patch failed: sub/folder/structure/third.xml:1
error: sub/folder/structure/third.xml: patch does not apply
error: patch failed: sub/folder/structure/forth.xml:1
error: sub/folder/structure/forth.xml: patch does not apply
error: patch failed: sub/folder/structure/fifth.xml:1
error: sub/folder/structure/fifth.xml: patch does not apply
Unfortunately applying the change failed!
//depot/perforce/workspace/sub/folder/structure/first.xml#1 - was edit, reverted
//depot/perforce/workspace/sub/folder/structure/second.xml#3 - was edit, reverted
//depot/perforce/workspace/sub/folder/structure/third.xml#3 - was edit, reverted
//depot/perforce/workspace/sub/folder/structure/forth.xml#3 - was edit, reverted
//depot/perforce/workspace/sub/folder/structure/fifth.xml#3 - was edit, reverted
No commits applied.

那个错误看起来很像这个错误:

git-p4提交失败,错误提示为“补丁无法应用”

但是我并没有进行任何关键词替换,所以我不知道可能是什么原因。添加--verbose似乎也不能帮助解释太多(我手头没有该命令的输出)

唯一的变化可能就是在我提交时添加了一个.gitattributes文件,其内容如下。然而,在该gitattributes文件存在的情况下,之前进行的提交确实有效,因此不能是这个问题(我后来对.gitattributes文件进行了更详细的修改)

* text eol=lf

我已经尝试将远程存储库中的提交回滚到这个有问题的提交之前,然后从我的存储库将它们推送到这个远程存储库并重新提交。但是结果一样。我还尝试了回滚并对同一文件进行不同的编辑,然后再次推送和重新提交,但仍然出现相同的问题。而且只在这些文件中才会出现这种情况。自从回滚以来,我尝试对其他文件进行编辑,它们可以正常工作。我尝试运行dos2unix强制将有问题的文件转换为Unix行结尾,但也没有解决问题。
有什么命令可以更好地解释这里发生了什么?是否有一个git日志文件我可以跟踪?任何帮助都将不胜感激。
编辑:我已经测试过我的问题,无论是否有.gitattributes文件都是一样的。目前我的全局core.autocrlf设置为input。但是在缺少.gitattributes文件的情况下,似乎没有任何区别。以下是我使用--verbose选项对其中一个有问题的文件重新测试时的情况。
user@hostname:/code$ git p4 submit -M --export-labels --verbose
Reading pipe: git name-rev HEAD
Reading pipe: ['git', 'config', 'git-p4.allowSubmit']
Reading pipe: git rev-parse --symbolic --remotes
Reading pipe: git rev-parse p4/master
Reading pipe: git cat-file commit 0457c7589ea679dcc0c9114b34f8f30bc2ee08cf
Reading pipe: git cat-file commit HEAD~0
Reading pipe: git cat-file commit HEAD~1
Reading pipe: ['git', 'config', 'git-p4.conflict']
Origin branch is remotes/p4/master
Reading pipe: ['git', 'config', '--bool', 'git-p4.useclientspec']
Opening pipe: ['p4', '-G', 'where', '//depot/perforce/workspace/...']
Perforce checkout for depot path //depot/perforce/workspace/ located at /home/user/Source/git-p4-area/perforce/workspace/
Synchronizing p4 checkout...
... - file(s) up-to-date.
Opening pipe: p4 -G opened ...
Reading pipe: ['git', 'rev-list', '--no-merges', 'remotes/p4/master..master']
Reading pipe: ['git', 'config', '--bool', 'git-p4.skipUserNameCheck']
Reading pipe: ['git', 'config', 'git-p4.detectCopies']
Reading pipe: ['git', 'config', '--bool', 'git-p4.detectCopiesHarder']
Reading pipe: ['git', 'show', '-s', '--format=format:%h %s', 'ef3b95f5fec193fe2612b28e2e3b5e7f8ba9419e']
Applying ef3b95f making test change
Opening pipe: p4 -G users
Reading pipe: ['git', 'log', '--max-count=1', '--format=%ae', 'ef3b95f5fec193fe2612b28e2e3b5e7f8ba9419e']
Reading pipe: git diff-tree -r -M "ef3b95f5fec193fe2612b28e2e3b5e7f8ba9419e^" "ef3b95f5fec193fe2612b28e2e3b5e7f8ba9419e"
//depot/perforce/workspace/sub/folder/structure/first.xml#3 - opened for edit
<stdin>:17: trailing whitespace.
<!-- comment line 1 -->
<stdin>:18: trailing whitespace.
<!-- comment line 2 -->
<stdin>:19: trailing whitespace.
<!-- comment line 3 -->
error: patch failed: sub/folder/structure/first.xml:1
error: sub/folder/structure/first.xml: patch does not apply
Unfortunately applying the change failed!
Reading pipe: ['git', 'config', '--bool', 'git-p4.attemptRCSCleanup']
//depot/perforce/workspace/sub/folder/structure/first.xml#3 - was edit, reverted
No commits applied.
Reading pipe: ['git', 'config', '--bool', 'git-p4.exportLabels']
Opening pipe: ['p4', '-G', 'labels', '//depot/ipstor.maple/automation/...']
Reading pipe: ['git', 'tag']
Reading pipe: ['git', 'config', 'git-p4.labelExportRegexp']

我猜试一下 git diff-tree -r -M "ef3b95f5fec193fe2612b28e2e3b5e7f8ba9419e^" "ef3b95f5fec193fe2612b28e2e3b5e7f8ba9419e" 然后看是否可以手动应用补丁? - Douglas Leeder
3个回答

3
我想通了。问题是由于行尾引起的。我用不同的文件重新测试了一下这个问题,在这种情况下,错误是由perforce工作区中检出的文件的行结尾是win风格的crlf,而git仓库中的文件的行结尾是unix风格的lf引起的。
在这种情况下,我在perforce中检出文件,运行dos2unix,然后提交,然后运行git p4提交,它就可以工作了。
那不是真正的解决方案。那只是一个权宜之计。我向git的邮件列表发送了一封电子邮件,请求修复。 http://marc.info/?l=git&m=136630231402536&w=2

3
对我来说,设置git config apply.ignorewhitespace change后提交成功了。
我认为错误是因为默认情况下git core.whitespace设置很严格导致的:
引用:

默认开启的有blank-at-eol,它查找行末尾的空格; blank-at-eof,它注意到文件末尾的空行; 以及space-before-tab,它查找行首的制表符之前的空格。

(请参见http://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration
设置apply.ignorewhitespace change允许git apply修复这些错误。更改core.whitespace设置以减少限制也应该可以解决问题,但我尚未尝试过。

0
请注意,如果您不进行rebase操作,则git p4 submit可能会失败。因此,请确保在提交之前运行git p4 rebase

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接