Git:我如何找到最接近目录的提交? [英] Git: How can I find a commit that most closely matches a directory?

查看:119
本文介绍了Git:我如何找到最接近目录的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人拿了一个Moodle的版本(我不知道),在一个目录中应用了很多改变,并且发布了它( tree here )。



如何确定原始项目的哪个提交最有可能编辑以形成这棵树?



这将允许我在此补丁的适当提交下形成一个分支。当然,它来自 1.8 1.9 分支,可能来自发布标签,但是在特定的提交之间进行区分并不会对我有多大帮助。



事后更新: knittl的答案让我尽可能接近我将要得到的。我首先添加了我的补丁回购作为远程外国(没有共同的承诺,没关系),然后在循环中与一些格式选项差异。第一个使用 - shortstat 格式:

  (git rev-list v1.9.0 ^ .. v1.9.5); do 
git diff --shortstat$ REVf7f7ad53c8839b8ea4e7 - mod / assignment>> 〜/ rdiffs.txt;
回显$ REV>> 〜/ rdiffs.txt;
完成;

第二只是统计差异时的行变化,没有上下文:

  for REV in $(git rev-list v1.9.0 ^ .. v1.9.5);做
git diff -U0$ REVf7f7ad53c8839b8ea4e7 - mod / assignment | wc -l>> 〜/ rdiffs2.txt;
回显$ REV>> 〜/ rdiffs2.txt;
完成;

有数千次提交需要挖掘,但这一个似乎是最接近的匹配。

解决方案

您可以编写一个脚本,它会将给定的树与存储库中的修订范围进行比较。假设我们首先将更改的树(没有历史记录)提取到我们自己的仓库:

  git remote add foreign git:// ... 
git fetch foreign

code>

然后我们为每个我们想要匹配的版本输出diffstat(简写):

 用于$(git rev-list 1.8 ^ .. 1.9)中的REV。做
git diff --shortstat foreign / master $ REV;
完成

寻找具有最小变化量的提交(或者使用一些排序机制)

Someone took a version (unknown to me) of Moodle, applied many changes within a directory, and released it (tree here).

How can I determine which commit of the original project was most likely edited to form this tree?

this would allow me to form a branch at the appropriate commit with this patch. Surely it came from either the 1.8 or 1.9 branches, probably from a release tag, but diffing between particular commits doesn't help me much.

Postmortem Update: knittl's answer got me as close as I'm going to get. I first added my patch repo as the remote "foreign" (no commits in common, that's OK), then did diffs in loops with a couple format options. The first used the --shortstat format:

for REV in $(git rev-list v1.9.0^..v1.9.5); do 
    git diff --shortstat "$REV" f7f7ad53c8839b8ea4e7 -- mod/assignment >> ~/rdiffs.txt; 
    echo "$REV" >> ~/rdiffs.txt; 
done;

The second just counted the line changes in a unified diff with no context:

for REV in $(git rev-list v1.9.0^..v1.9.5); do 
    git diff -U0 "$REV" f7f7ad53c8839b8ea4e7 -- mod/assignment | wc -l >> ~/rdiffs2.txt;
    echo "$REV" >> ~/rdiffs2.txt; 
done;

There were thousands of commits to dig through, but this one seems to be the closest match.

解决方案

you could write a script, which diffs the given tree against a revision range in your repository.

assume we first fetch the changed tree (without history) into our own repository:

git remote add foreign git://…
git fetch foreign

we then output the diffstat (in short form) for each revision we want to match against:

for REV in $(git rev-list 1.8^..1.9); do
   git diff --shortstat foreign/master $REV;
done

look for the commit with the smallest amount of changes (or use some sorting mechanism)

这篇关于Git:我如何找到最接近目录的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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