I would like to compare 2 branches and show the commits that exist in one but not the other. This works from command line git log --pretty=oneline branch_b ^branch_a --no-merges
and gives me what I want but I would like to simulate the same thing in Grit to gain working with the object instead of strings. Is this possible in Grit?
Asked
Active
Viewed 295 times
0

Adam
- 1,561
- 2
- 15
- 25
-
I don't know anything about grit but "show the commits that exist in one but not the other" sounds like exactly what [`git cherry`](http://www.kernel.org/pub/software/scm/git/docs/git-cherry.html) is for. Maybe that will give you something to Google for... – Tyler Jul 14 '12 at 19:46
1 Answers
0
I think something like this should do the trick:
require 'grit'
repo = Grit::Repo.new(".")
repo.commits_between("branch_b", "branch_a")
See http://grit.rubyforge.org/classes/Grit/Repo.html#M000227 for doc ( http://grit.rubyforge.org/ for full doc).
This will give you commit objects in an array though, it doesn't format the output like the git command does. Also, it doesn't exclude the merge commits.
In order to get formatted output, try something like this:
puts repo.commits_between("branch_b", "branch_a").map { |c| ["*", c.id_abbrev, c.authored_date.to_date, c.short_message] * " " }

S. Christoffer Eliesen
- 1,076
- 1
- 7
- 6