6

我尝试在我一直在运行的 repo 上运行 git p4 submit 作为 git 和 perforce 之间的临时桥梁。多人将 repo 用作遥控器,并定期将其提交回 perforce。

它一直工作得很好,除了一些重复的 perforce 提交,它们的奇怪行为我似乎无法重现。然后有一天我突然收到了这个错误。我不能再推动任何 git 提交来执行。

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 设置是输入。但是缺少 .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']
4

3 回答 3

3

我想到了。该问题是由行尾引起的。我用不同的文件重新测试了这个问题,在这种情况下,错误是由于在 perforce 工作区中签出的文件的行结尾是 win 样式 crlf,而 git repo 中文件的行结尾是 unix 样式如果。

在这种情况下,我在 perforce 中检查了该文件,对它运行 dos2unix 并提交,然后运行 ​​git p4 submit 并且它工作。

这不是真正的解决方案。这只是解决方法。我向 git 的邮件列表发送了一封电子邮件,请求修复。http://marc.info/?l=git&m=136630231402536&w=2

于 2013-04-18T18:07:43.220 回答
3

对我来说,在我设置后提交工作git config apply.ignorewhitespace change

我认为发生错误是因为 gitcore.whitespace设置在默认情况下是限制性的:

默认开启的是blank-at-eol,在行尾查找空格;blank-at-eof,注意文件末尾的空白行;和空格前制表符,它在行首的制表符之前查找空格。

(见http://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration

设置apply.ignorewhitespace change允许git apply修复这些错误。将设置更改为core.whitespace限制较少也应该可以解决问题,但我没有尝试过。

于 2015-01-30T09:57:30.023 回答
0

请注意,git p4 submit如果您不进行变基,则可能会失败。所以一定要git p4 rebase在提交前运行。

于 2019-07-30T14:44:11.417 回答