将上下文差异转换为统一差异格式
Convert a context diff to unified diff format
我收到了上下文差异格式的补丁,我需要在Git中应用它。据我所知,Git只能应用统一差异格式的补丁。
有没有办法将上下文差异转换为统一差异格式,以便我可以 git apply
修改后的补丁?
由于 git diff
只能配置为 produce a context diff (or be filtered to produce one), a possible simple approach would be to use patch
以手动应用上下文差异,然后使用 git add
检测更改。
这是我最近在寻找同一问题的解决方案时找到的解决方案。
使用 quilt:
dev-util/quilt-0.65::gentoo was built with the following:
USE="-emacs -graphviz" ABI_X86="(64)"
从 gentoo 和以下命令行会话,我能够轻松地
将上下文差异转换为统一差异,并将条带级别(补丁中的选项 -p)从 -p0 调整为 -p1(总是使用 -p1 伙计们,这会让你和其他人的生活更轻松!)
$ tar xf SDL2-2.0.8.tar.gz
$ cd SDL2-2.0.8
$ quilt new SDL2-2.0.8.unified.patch
$ quilt --quiltrc - fold -p 0 < ../SDL2-2.0.8.context.patch # arbitrary -p0 context diff I created for this exercise
$ quilt refresh
# your new -p1 unified diff can be found at SDL2-2.0.8/patches/SDL2-2.0.8.unified.patch
在此处回答此问题,因为这是 google 中与将上下文差异转换为统一差异相关的查询的最高结果之一。
应该在任何发行版中工作,我只是为了后代的缘故准确报告我所拥有的。
刚刚找到 'better' 方法,但需要自己的准备工作。为此,您只需要补丁文件本身。您将需要 patchutils
dev-util/patchutils-0.3.4::gentoo was built with the following:
USE="-test" ABI_X86="(64)"
$ $EDITOR SDL2-2.0.8.context.patch
# remove all lines like: 1 diff -cr SDL2-2.0.8/src/SDL.c SDL2-2.0.8.new/src/SDL.c (apparently not needed in current git)
# save and quit
$ filterdiff --format=unified < SDL2-2.0.8.context.patch > SDL2-2.0.8.unified.patch
# you can even do this inside vim with
:%!filterdiff --format=unified
希望对您有所帮助!
我收到了上下文差异格式的补丁,我需要在Git中应用它。据我所知,Git只能应用统一差异格式的补丁。
有没有办法将上下文差异转换为统一差异格式,以便我可以 git apply
修改后的补丁?
由于 git diff
只能配置为 produce a context diff (or be filtered to produce one), a possible simple approach would be to use patch
以手动应用上下文差异,然后使用 git add
检测更改。
这是我最近在寻找同一问题的解决方案时找到的解决方案。 使用 quilt:
dev-util/quilt-0.65::gentoo was built with the following:
USE="-emacs -graphviz" ABI_X86="(64)"
从 gentoo 和以下命令行会话,我能够轻松地 将上下文差异转换为统一差异,并将条带级别(补丁中的选项 -p)从 -p0 调整为 -p1(总是使用 -p1 伙计们,这会让你和其他人的生活更轻松!)
$ tar xf SDL2-2.0.8.tar.gz
$ cd SDL2-2.0.8
$ quilt new SDL2-2.0.8.unified.patch
$ quilt --quiltrc - fold -p 0 < ../SDL2-2.0.8.context.patch # arbitrary -p0 context diff I created for this exercise
$ quilt refresh
# your new -p1 unified diff can be found at SDL2-2.0.8/patches/SDL2-2.0.8.unified.patch
在此处回答此问题,因为这是 google 中与将上下文差异转换为统一差异相关的查询的最高结果之一。
应该在任何发行版中工作,我只是为了后代的缘故准确报告我所拥有的。
刚刚找到 'better' 方法,但需要自己的准备工作。为此,您只需要补丁文件本身。您将需要 patchutils
dev-util/patchutils-0.3.4::gentoo was built with the following:
USE="-test" ABI_X86="(64)"
$ $EDITOR SDL2-2.0.8.context.patch
# remove all lines like: 1 diff -cr SDL2-2.0.8/src/SDL.c SDL2-2.0.8.new/src/SDL.c (apparently not needed in current git)
# save and quit
$ filterdiff --format=unified < SDL2-2.0.8.context.patch > SDL2-2.0.8.unified.patch
# you can even do this inside vim with
:%!filterdiff --format=unified
希望对您有所帮助!