3

我没有找到任何关于在崎岖不平的情况下获得 2 个文件之间差异的文档。我使用下面的代码使用坚固的提交文件

@repo=Rugged::Repository.new($reponame)
@sha=@repo.write('D:\Ruby\MyGitRepo\file1.txt','blob')
puts @sha
commit = @repo.lookup(@sha)

如何在崎岖不平的环境中看到同一对象的 2 次提交之间的差异?

4

1 回答 1

4

在 git 中比较两个提交的方法依赖于一个差异过程。

brianmario最近包装了libgit2的差异迭代器功能。请注意,此功能尚未合并

下面是其未来使用的高级示例。

r = Rugged::Repository.new('.')
diff = r.diff(commit1, commit2)

diff.deltas.each do |delta|
  # ...
  delta.hunks.each do |hunk|
    # ...
    hunk.lines.each do |line|
      # ...
    end
  end
end

有关提议的差异实现和使用的更多信息,请参阅此拉取请求

于 2013-01-18T07:39:13.093 回答