我希望能够在两个Grit::Commit
对象之间进行分析,这是更新的对象。我的意思是,如果commit_A
是commit_B
的父母(或父母的父母等),那么commit_B
是更新的。这假定commit_A
和commit_B
位于同一分支上。
我考虑使用Grit::Commit#date()
,但我认为这将是不准确的。
有什么想法吗?
答案 0 :(得分:1)
这是我最终实施的内容。请参阅注释以获得解释
性能很慢,但使用repo.git.rev_list(通过method_missing)时效果更差。
require 'grit'
module Grit
class Commit
# Returns true if any commits in +commits+ are decendants of calling commit. True
# means that one or more commits in +commits+ are newer.
def has_decendant_in? *commits
total_commits = commits.flatten
raise ArgumentError "at least one commit required." if total_commits.empty?
total_commits.each do |commit|
return true if repo.commits_between(commit.id, id).empty?
end
return false
end
# Returns an Array of commits which tie for being the newest commits. Ties can
# occur when commits are in different branches.
def self.newest *commits
oldest_commits = []
total_commits = commits.flatten
raise ArgumentError "at least one commit required." if total_commits.empty?
(total_commits).each do |commit|
if commit.has_decendant_in?(total_commits - [commit])
oldest_commits << commit
end
end
return total_commits - oldest_commits
end
end
end
答案 1 :(得分:0)
以下将是你的帮助...... git log --graph或你可以使用gitk