我会想到的一般是:
- 找到含义为“如果标签包含此提交,则它包含更改”的提交列表
- 将包含这些提交的所有标签组合在一起
最难的部分是确定 1.,所以首先是最简单的部分:
# in a file, or as the output of a commit :
eacf32c
44df701
...
只需重复运行git tag --contains,并将结果合并在一起:
cat thelist.txt | while read sha; do git tag --contains $sha; done | sort -u
这在很大程度上取决于您打算如何针对上述更改。下面是一些例子:
-
如果您知道您只想针对使用 git cherry-pick 应用的提交,提交消息可能会非常相似:git log --all --grep "one discriminating sentence" 或 git log --all --grep "#issuenumber" 可能会给您一个很好的起点
-
如果您想针对添加或删除特定行的提交:从git log --all -S "a specific line" 或git log --all -G "a specific line" 开始(如果您需要更多关于它们如何工作的解释,请阅读the doc for -S and -G)。
您还可以通过运行发现that/specific/file.txt 或that/specific/dir 的变化:
git log -S "a specific line" -- that/specific/file.txt
git log -G "a specific line" -- that/specific/dir
- 如果您想发现在您的代码库中引入了完全相同的补丁的提交,事实证明 git 有一个算法:
git patch-id
(注意:在git rebase 中使用它来发现已经应用于目标的提交)
在你的 repo 提交的完整列表中使用它会有点复杂,但它可以自动化:
首先计算您想要发现的更改的补丁 ID:
$ git show A | git patch-id --stable
# this will give you a two fields output :
# a hash for the diff itself the hash of the commit
3bbe48e8ce5714b78900653e618ff4dc41205ffb 84d48dcd44d440d3a35177c92c897d2efae93346
然后计算所有补丁 id,然后用 grep 找到你想要的:
git rev-list --all | while read sha; do git show $sha | git patch-id; done
| grep "^3bbe48e8ce5714b78900653e618ff4dc41205ffb"
第二列将是提交列表:... | awk '{ print $2 }'
git show $sha -- file1 file2 dir3 | git patch-id
注意:如果您有一个git log 命令可以让您发现一些您感兴趣的提交,您可以通过删除所有格式选项(--onelin、@ 987654346@, --format ...) 并将它们替换为--format="%H"