我目前正在对一个(github)存储库的PR进行代码样式检查,并希望向提交者提供补丁,以便他们可以轻松地修复代码样式问题。为此,我会拉取他们的PR,运行我们的uncrustify脚本来修复任何样式错误,并想要创建一个他们可以轻松应用的 .patch 文件。然而,它在某些文件上始终出现问题。
我使用的是git版本1.7.10.4,其中包括core.autocrlf=input
和core.filemode=false
:
$ git checkout pr-branch
$ git log -1 (shows: commit dbb8d3f)
$ git status (nothing to commit, working directory clean)
$ <run the code styler script, which modifies some files>
$ git diff > ../style.patch (so the patch file lands outside the repo)
$ git reset --hard HEAD (to simulate the situation at the submitter's end)
$ git log -1 (shows: commit dbb8d3f)
$ git status (nothing to commit, working directory clean, so we are where we started)
$ git apply ../style.patch
error: patch failed: somefile.cpp:195
error: somefile.cpp: patch does not apply (same output using the --check option)
这仅适用于某些文件,而不是全部文件。我不知道如何进行故障排除,即如何让git告诉我出错的具体位置 - 它只告诉我一个巨大的hunk#。
到目前为止我尝试过以下方法(但都没有成功):
apply --reverse
,apply --whitespace=nowarn
- 使用
diff HEAD
代替单独的diff
- 创建一个虚拟提交(提交不会有问题!),使用
format-patch
,删除虚拟提交,使用git-am
或git-apply
打补丁,有或没有加上-3
- 将补丁文件放在本地目录中,而不是在上一级(纯属瞎猜)
- 查看git-diff、-apply、-format-patch、-am的手册是否有有用的信息
- 使用Linux的
patch
命令打补丁 - ....
我不知道diff可能出了什么问题。空格应该只会发出警告,对吧?无论如何,我不想忽略它们,因为这是一个显然涉及空格的样式修复。
我该如何修复/诊断这个问题,甚至找出它究竟在哪里失败?如果我发布一个有问题的文件的diff,是否会有所帮助?令我困惑的是提交没有问题,但从提交创建的补丁却有问题?
在苦苦挣扎了数个小时后,我的知识已经耗尽了...
git apply --reject
命令以查看被拒绝的更改。 - aragaer--whitespace=fix
,但我仍然不明白为什么,因为我只是创建了补丁,没有手动编辑它。 - torvin