-
-
Save mmorey/8125388 to your computer and use it in GitHub Desktop.
Git commit logger for keeping track on what you work on
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Write git commit messages to a log file | |
# | |
# Lincoln A. Mullen | lincoln@lincolnmullen.com | http://lincolnmullen.com | |
# MIT License <http://lmullen.mit-license.org/> | |
# | |
# You will have to install the git gem for this to work: | |
# gem install git | |
# | |
# You will need to make the script executable | |
# chmod +x post-commit | |
# | |
# Name this file 'post-commit' and drop it in the directory '.git/hooks' in | |
# any repository that you want to log. Make sure the file is executable. You | |
# can also add this to your git templates, which will put it in every new | |
# repository or to existing repositories by re-running git init. | |
# | |
# A commit message in the log should look this this: | |
# 2013-07-26-11-25-55 [repository:branch] First line of commit message | |
require "git" | |
log_file = ENV['HOME'] + "/commit_log.txt" | |
repo = Git.open(Dir.pwd) | |
repo_name = Dir.pwd[%r{[\.\-\w]+$}] # top directory | |
date = repo.log.first.date.strftime("%Y-%m-%d-%H-%M-%S") # format date | |
message = repo.log.first.message.lines.first.strip # just first line | |
branch = repo.log.first.name | |
File.open(log_file, "a") do |log| | |
log.puts "#{date} [#{repo_name}:#{branch}] #{message}" | |
puts "#{date} [#{repo_name}:#{branch}] #{message}" | |
end | |
puts "Updated #{log_file}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment