如何使用 Grit 找出提交之间更改了哪些文件

发布于 2024-09-05 12:09:25 字数 1206 浏览 7 评论 0原文

我在尝试找出两个不同提交之间更改了哪些文件时遇到问题。以下是 Ruby 和 Gem Grit 的设置、版本,以及运行该程序时发生的情况:

> 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

这是 ruby​​ 程序:

require 'rubygems'
require 'grit'
include Grit
File.open('t1.txt', 'w') { |f| f.write('hi/bye') }
repo = Repo.new('.')
repo.add('.')
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

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.add('.')
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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹过旳痕迹 2024-09-12 12:09:25

您可以使用

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

来获取两个提交的列表

you can use

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

to get list of the two commit

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文