git p4提交:修补程序不适用
最近我在使用git-p4时遇到了一些问题 我当前的工作流程是:git p4提交:修补程序不适用,git,perforce,git-p4,Git,Perforce,Git P4,最近我在使用git-p4时遇到了一些问题 我当前的工作流程是: git checkout -b some_feature # do some work and commit to some_feature branch git checkout master git merge --no-ff some_feature git p4 rebase git p4 submit 不总是,但偶尔在执行git p4 submit时,更改实际上并不适用,相反,我看到: error: some_file.
git checkout -b some_feature
# do some work and commit to some_feature branch
git checkout master
git merge --no-ff some_feature
git p4 rebase
git p4 submit
不总是,但偶尔在执行git p4 submit
时,更改实际上并不适用,相反,我看到:
error: some_file.extension: patch does not apply
在做一些研究时,我尝试过在master上进行硬重置,并在没有--no ff
标志的情况下再次合并,但这似乎没有帮助
非常感谢您的任何想法。我也遇到了同样的问题,我认为根本原因是行尾。您可以尝试运行类似于
dos2unix
的东西来修复它,或者设置此配置:
git config --global core.autocrlf true
有时,文件模式可能会导致出现问题。此配置可以修复它(如果您不关心文件模式):
我今天碰到了这个问题。在我的例子中,问题是因为我的文本编辑器(VisualStudio)在它接触的每个文件中都添加了一个。同时,Perforce服务器被设置为从每个文件中剥离Unicode BOM,从而防止Unicode BOM出现在Perforce中。这最终导致my
git p4 submit
失败,并显示以下消息:
error: patch failed: path/to/file.csproj:1
error: path/to/file.csproj: patch does not apply
最终解决方案
我在我的~/.gitconfig文件中添加了以下过滤器定义:
[filter "utf8-autobom"]
clean = sed -b -e '1!b' -e 's/^\\xEF\\xBB\\xBF//'
smudge = sed -b -e '1!b' -e 's/\\(^\\|^\\xEF\\xBB\\xBF\\)/\\xEF\\xBB\\xBF/'
然后我通过在.gittributes中添加以下行,将utf8 autobom
过滤器应用于有问题的文件:
*.csproj filter=utf8-autobom
然后,我强制Git使用以下命令将过滤器应用于其索引:
rm .git/index
git reset
然后我将编辑过的文件提交给Git,并像往常一样提交给Perforce:
git add .
git commit --amend
git p4 submit
工作原理
过滤器定义基于以下sed
命令,其中“abc”是相应Unicode BOM字节序列的占位符:
# Remove 'abc' from beginning of file, if present
sed -b -e '1!b' -e 's/^abc//'
# Add 'abc' to beginning of file, if not present
sed -b -e '1!b' -e 's/\(^\|^abc\)/abc/'
对于UTF-8 BOM,我们使用字节序列EF BB BF
而不是“abc”
过滤器通过运行clean
命令在提交时删除BOM表,并通过运行smudge
命令在签出时添加BOM表。这会将BOM保存在工作树文件中,但会阻止将BOM提交给Git或提交给Perforce
(有关清洁
和污迹
的详细信息,请参阅)
诊断问题
我认为错误消息很有趣:
error: patch failed: path/to/file.csproj:1
error: path/to/file.csproj: patch does not apply
它说补丁在第1行失败,即使我的提交没有编辑文件的第1行
为了了解发生了什么,我运行了git diff p4/master HEAD
。差异显示我的提交在文件开头添加了一个奇怪的
字符。我怀疑这与文件编码有关,所以我使用Notepad++在我的Git工作树中打开文件。然后,我在Perforce工作区中打开了相应的文件。Notepad++在我的Git工作树中将编码显示为“UTF-8-BOM”,在我的Performce工作区中将编码显示为“UTF-8”。(Linux和Cygwin用户:使用file
命令显示有关文件编码的信息。)
谷歌搜索“UTF-8-BOM”让我走上了正确的道路
通知
安装此筛选器后,某些Git操作将变慢
提示
如果工作树中不需要BOM表,可以删除过滤器的污迹部分。这将加快一些Git操作(如Git签出
)。删除污迹
行后,过滤器定义为:
[filter "utf8-autobom"]
clean = sed -b -e '1!b' -e 's/^\\xEF\\xBB\\xBF//'
这两个对你有用吗?
[filter "utf8-autobom"]
clean = sed -b -e '1!b' -e 's/^\\xEF\\xBB\\xBF//'