In ruby/grit, how do I get a list of files changed in a specific commit?

一个人想着一个人 提交于 2019-12-13 00:14:06

问题


I want a list of files affected by a certain commit in git. Through the command line, I can do this with:

git show --pretty="format:" --name-only (sha)

But how can I do this through Grit in Ruby?


回答1:


You can use your_commit.diffs which returns an array of Grit::Diff instances. Grit::Diff has a_path and b_path properties.

Some (untested) example code:

paths = [];
@commit.diffs.each do |diff|
    paths += [diff.a_path, diff.b_path]
end
paths.uniq!



回答2:


Since Grit's git module employs method_missing to shell out, you can also try:

grit.git.show({ :pretty => :format, :name_only => true}, sha)



来源:https://stackoverflow.com/questions/4948042/in-ruby-grit-how-do-i-get-a-list-of-files-changed-in-a-specific-commit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!