开发者

How do you find out what files where changed between commits using Grit

开发者 https://www.devze.com 2023-01-03 08:41 出处:网络
I am having trouble trying to find out what files changed between two different commits. Here is the setup, version of Ruby and the Gem Grit, and what happens when I run the program:

I am having trouble trying to find out what files changed between two different commits. Here is the setup, version of Ruby and the Gem Grit, and what happens when I run the program:

> cd /temp
> mkdir tt
> cd tt
> git init
Initialized empty Git repository in C:/temp/tt/.git/
> ruby --version
ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32]
> gem list grit
*** LOCAL GEMS ***
grit (2.0.0)
> ruby ..\git_diff_test.rb
Commit #1 succeeded.
Commit #2 succeeded.
c:/apps/ruby/lib/ruby/gems/1.8/gems/grit-2.0.0/lib/grit/repo.rb:290:in `diff': wrong number of arguments (4 for 3) (ArgumentError)
        from c:/apps/ruby/lib/ruby/gems/1.8/gems/grit-2.0.0/lib/grit/repo.rb:290:in `diff'
        from ../git_diff_test.rb:13

Here is the ruby program:

require 'rubygems'
require 'grit'
include Grit
File.open('t1.txt', 'w') { |f| f.write('hi/bye') }
repo = Repo.new('.')
repo.开发者_StackOverflowadd('.')
puts "Commit #1 #{repo.commit_all('1') ? 'succeeded' : 'failed'}."
File.open('t1.txt', 'w') { |f| f.write('hi/bye twice') }
File.open('t2.txt', 'w') { |f| f.write('hi/bye 2') }
repo.add('.')
puts "Commit #2 #{repo.commit_all('2') ? 'succeeded' : 'failed'}."
commits = repo.commits
the_diff = repo.diff(commits[0], commits[1])  # line 13 with the error
p the_diff


you can use

grit.commits_between('HASH1', 'HASH2')

to get list of the two commit

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号