rubyrubygemsgrit

grit equivalent of git diff


I am trying to find all the lines of code within the current git diff that have been deleted (in the unstaged changes) using the ruby gem grit, i.e. I want to see all the unstaged changes involving deletions. This would be the equivalent of doing git diff -U0 | grep ^-[^-] in the shell.

So far I have only been able to figure out how to get the diffs between two commits, or get the names of the files that have been changed.


Solution

  • Try as follows:

    diff = @repo.git.diff({:U0 => true}).split( "\n" ).grep( /^-[^-]/ ).join( "\n" )