How to display the git last commit of every file in a list with ruby

Problem

You want to display the last commit of every file that you have in a list.

Solution

Let’s say that you have the following file list in an array:

file_list = ["Gemfile", "Gemfile.lock", ".ruby-version"]

in order to be able to get the last commits of each of the files in ruby do the following:

file_list.each do |f|
  puts %x[git log -n 1 #{f}]
end