查找 git commit 产生的一些代码 [英] Finding what git commit some code spawned from

查看:28
本文介绍了查找 git commit 产生的一些代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些 Linux 内核修改版的原始开源代码.理想情况下,我会有一个补丁,这样我就可以将它应用到内核的较新版本,但我只有源代码,所以我正在尝试自己创建该补丁.

I have some raw open-source code for a modified version of the linux kernel. Ideally I would have a patch so that I could apply it to a newer version of the kernel, but instead I just have the source code, so I'm trying to create that patch myself.

我发现,当我创建补丁并将其应用到较新的内核时,我最终会恢复很多更改.git 中是否有一项功能可以判断本地更改是否正在恢复以前的提交?或者有没有其他工具可以找到更改最少的提交(即使它很耗时并且必须在我自己的机器上运行)?

What I'm finding is that when I create a patch and apply it to the newer kernel, I end up reverting a lot of changes. Is there a feature in git that can tell if local changes are reverting previous commits? Or is there some other tool that can find the commit with the least amount of changes (even if it's time consuming and has to be run on my own machine)?

我一直在手动缩小源分支的提交范围,但这非常耗时.我找到了一个非常匹配的分支,现在我想弄清楚在对其进行更改之前最新的提交是什么.

I've been manually narrowing down what commit the source branched from, but it's very time consuming. I found a branch that fairly closely matched and now am trying to figure out what the latest commit was before changes were made to it.

我将检查提交 A,复制已更改的文件,对任何删除了大量内容的文件进行日志记录,以确定这些更改是否是从提交 B 添加的,然后在提交之前检查该提交B、等等等等……

I'll check out a commit A, copy the changed files, do a log on any file that has a lot of stuff taken out to find out if those exact changes were added from commit B, then checkout the commit before commit B, etc, etc...

由于这一切都与开源代码有关,我看不出有什么理由不能在此处共享指向它的链接.

Since this is all pertaining to open source code, I don't see any reason why I can't share links to it here.

可以在此处找到 LGE 发布的源代码.在手机下搜索 LS970.

The source code released by LGE can be found here. Search for LS970 under Mobile.

可以找到 MSM 内核的不同分支 此处.到目前为止,ics_strawberry 头似乎是最接近的.它是为数不多的具有 chromeos 文件夹的文件夹之一,似乎专门为不运行 Chrome 操作系统的手机添加该文件夹是一件很奇怪的事情.

The different branches of the MSM kernel can be found here. So far the ics_strawberry head seems to be the closest. It's one of the few that has a chromeos folder, which seems like it would be an odd thing to add specifically for a cell phone that wouldn't be running Chrome OS.

推荐答案

不幸的是,你不能在这里使用 git bisect 因为你无法在任何提交中判断它是好还是坏.

Unfortunately, you cannot use git bisect here because you cannot tell at any commit whether it was bad or good.

您的目标是找到与您的目标源最匹配的提交.我认为最佳匹配"的最佳指标是统一差异/补丁的大小(以行为单位).

Your goal is to find commit that matches best to your target source. I think that best metric of what is "matching best" is the size (in lines) of unified diff/patch.

考虑到这一点,您可以根据以下伪代码编写脚本(抱歉,shell、Perl 和 C 的奇怪组合):

With this in mind, you can write a script according to following pseudo-code (sorry, weird mix of shell, Perl and C):

min_diff_size = 10000000000
best_commit = none
git branch tmp original_branch  # branch to scan
git checkout tmp
for (;;) {
    diff_size = `diff -burN -x.git my_git_subtree my_src_subtree | wc -l`;
    if (diff_size < min_diff_size) {
         min_diff_size = diff_size;
         best_commit = `git log --oneline -1`;
    }
    git reset --hard HEAD~; # rewind back by 1 commit
    if (git reset did not work) break;
}
git checkout original_branch
git branch -d tmp

print "best commit $best_commit, diff size $min_diff_size"

您可能还想遍历内核分支以找到最匹配的分支.

You may also want to cycle through kernel branches as well to find best matching branch.

这可能会运行缓慢并花费大量时间(可能是数小时),但它会找到最匹配的提交.

This probably will work slow and take a lot of time (could be hours), but it will find best matching commit.

这篇关于查找 git commit 产生的一些代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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