Git:想要遍历分支上的所有提交,并列出每个提交中的文件 [英] Git: want to iterate through all commits on branch, and list files in each commit
本文介绍了Git:想要遍历分支上的所有提交,并列出每个提交中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要编写一个脚本,它可以从最近的
开始遍历分支上的所有提交。- li>
- ,如果它发现了一个类型为hbm.xml的文件,将该提交存储到文件中,并遍历提交中的所有文件,退出。
我有第2步的脚本:
对于我在`git show --pretty =format:--name-only SHA1 | grep'。* \.hbm\.xml'`;在这里做
#脚本.....
退出
完成
解决方案
类似于:
$现在,我需要找出步骤1。 b $ b pre $
用于提交$(git rev-list $ branch)
做
如果git ls-tree --name-only -r $ commit | grep -q'\.hbm\.xml $';然后
echo $ commit
exit 0
fi
done
请注意, git show
将仅列出在该提交中已更改的文件,如果您想知道是否存在与提交中的特定模式相匹配的路径需要使用类似于 git ls-tree
。
I need to write a script that will
- iterate through all of the commits on a branch, starting from the most recent
- for each commit, iterate through all of the files in the commit
- if it finds a file of type hbm.xml, store the commit to file and exit.
I have a script for step 2:
for i in `git show --pretty="format:" --name-only SHA1 | grep '.*\.hbm\.xml' `; do
# call script here.....
exit
done
Now, I need to figure out step 1.
解决方案
Something like:
for commit in $(git rev-list $branch)
do
if git ls-tree --name-only -r $commit | grep -q '\.hbm\.xml$'; then
echo $commit
exit 0
fi
done
Note that git show
will only list files which have changed in that commit, if you want to know whether there is a path that matches a particular pattern in a commit you need to use something like git ls-tree
.
这篇关于Git:想要遍历分支上的所有提交,并列出每个提交中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文