如何在 git 树的顶部应用补丁以防止重复? [英] How to apply patches on the top of a git tree preventing duplication?

查看:25
本文介绍了如何在 git 树的顶部应用补丁以防止重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

我的问题:我有一个 git 树(linux 内核)和一些补丁.会发生什么,这些补丁是为旧版本的内核设计的,其中许多已经应用于我的树.补丁以标题行开头,如

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)

并通过做类似的事情

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.

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

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

那么:是否有任何命令/实用程序可以检查当前树上是否已经应用了补丁,如果没有,它会执行git 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?

谢谢.

推荐答案

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

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

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

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.

这篇关于如何在 git 树的顶部应用补丁以防止重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆