gpt4 book ai didi

git - 将上下文差异转换为统一差异格式

转载 作者:太空狗 更新时间:2023-10-29 14:03:27 25 4
gpt4 key购买 nike

我收到了上下文差异格式的补丁,我需要在 Git 中应用它。据我所知,Git 只能应用统一差异格式的补丁。

有什么方法可以将上下文差异转换为统一差异格式,以便我可以 git apply 修改后的补丁?

最佳答案

这是我最近在寻找同一问题的解决方案时找到的解决方案。使用quilt :

dev-util/quilt-0.65::gentoo was built with the following:
USE="-emacs -graphviz" ABI_X86="(64)"

从 gentoo 和以下命令行 session ,我能够轻松地将上下文差异转换为统一差异,并将 strip 级别(补丁中的选项 -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

在这里回答这个问题,因为这是谷歌中与将上下文差异转换为统一差异相关的查询的最高结果之一。

应该在任何发行版中工作,为了后代,我只是准确地报告我所拥有的。

刚刚找到了一个“更好”的方法,但需要自己的准备工作。为此,您只需要补丁文件本身。您将需要 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 - 将上下文差异转换为统一差异格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50166072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com