如何在 git 树的顶部应用补丁以防止重复?

发布于 2024-09-12 04:10:25 字数 1071 浏览 3 评论 0原文

我正在为一个我认为很简单的问题寻求建议,并且通过创建一个小脚本确实可能很简单,但我认为应该已经有一种方法可以使用 git/quilt/stgit 来做到这一点。

我不太擅长 git,这给我带来了一些问题。

我的问题: 我有一个 git 树(linux 内核)和一些补丁。发生了什么,这些补丁是针对旧版本的内核的,其中许多已经应用到我的树上。这些补丁以标题行开头

From b1af4315d823a2b6659c5b14bc17f7bc61878ef4 (timestamp)

,通过在我的内核树中执行类似的操作

git show b1af4315d823a2b6659c5b14bc17f7bc61878ef4

,我可以看到它们已经在我当前的树中可用,并且我不想尝试应用它们。

我尝试使用 git applygit am 之类的东西,但他们似乎尝试应用补丁:

alan@ubuntu:~/Desktop/openwrt/linux-git/linux-2.6.33.y$ git apply -p1 --check --index        /home/alan/Desktop/openwrt/svn/backfire-branch/build_dir/linux-kirkwood/linux-    2.6.30.10/patches/generic/000-bzip_lzma_remove_nasty_hack.patch
error: patch failed: lib/decompress_bunzip2.c:45
error: lib/decompress_bunzip2.c: patch does not apply
error: patch failed: lib/decompress_unlzma.c:29
error: lib/decompress_unlzma.c: patch does not apply

那么:是否有任何命令/util 执行检查是否有补丁已经应用于当前树,如果没有,它会执行“git apply”,如果有,则跳过补丁?

谢谢。

I'm seeking advice for a problem that I thought to be simple, and it might be simple indeed by creating a small script, but I think there should already be a way to do that with git/quilt/stgit.

I'm not exactly good at git and this is causing some issues to me.

My problem:
I've got a git tree (linux kernel) and a number of patches. What happens, such patches were intended for and older version of the kernel, and many of them have already been applied to my tree. The patches start with an header line like

From b1af4315d823a2b6659c5b14bc17f7bc61878ef4 (timestamp)

and by doing something like

git show b1af4315d823a2b6659c5b14bc17f7bc61878ef4

in my kernel tree, I can see they're already available in my current tree, and I don't ever want to try applying them.

I tried using things like git apply or git am , but they seem to try applying the patch whatsoever:

alan@ubuntu:~/Desktop/openwrt/linux-git/linux-2.6.33.y$ git apply -p1 --check --index        /home/alan/Desktop/openwrt/svn/backfire-branch/build_dir/linux-kirkwood/linux-    2.6.30.10/patches/generic/000-bzip_lzma_remove_nasty_hack.patch
error: patch failed: lib/decompress_bunzip2.c:45
error: lib/decompress_bunzip2.c: patch does not apply
error: patch failed: lib/decompress_unlzma.c:29
error: lib/decompress_unlzma.c: patch does not apply

So: is there any command/util that performs a check whether a patch has already been applied on the current tree, and it does a "git apply" if it hasn't, and just skips the patch if it has?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云淡月浅 2024-09-19 04:10:25

您可以创建一个版本的新分支,为其制作补丁,然后应用它们并将临时分支合并到主版本中:

git checkout -b temp-branch v2.6.30
git apply/am ...patches...
git checkout master
git merge temp-branch

这应该解决大多数重复的补丁(尽管,它不会使用提交 ID,而是使用补丁内容)。另外,您可以在最后一步中尝试 git rebase 。

这不是最优雅的方式,但应该可以解决问题。

You can create a new branch of the version, for which the patches were made, than apply them and merge the temp-branch into master:

git checkout -b temp-branch v2.6.30
git apply/am ...patches...
git checkout master
git merge temp-branch

This should resolve most duplicated patches (although, it won't use the commit id, but rather patch contents). Also, you could try git rebase in the last step.

It's not the most elegant way, but should do the trick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文