Skip to content

Instantly share code, notes, and snippets.

@mmorey
Forked from lmullen/post-commit
Last active January 1, 2016 09:29
Show Gist options
  • Select an option

  • Save mmorey/8125388 to your computer and use it in GitHub Desktop.

Select an option

Save mmorey/8125388 to your computer and use it in GitHub Desktop.

Revisions

  1. mmorey revised this gist Dec 25, 2013. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions post-commit
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,9 @@
    # 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
    @@ -18,12 +21,14 @@

    require "git"

    log_file = "/home/lmullen/todo/time-use.txt"
    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}"
    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}"
  2. @lmullen lmullen created this gist Jul 27, 2013.
    29 changes: 29 additions & 0 deletions post-commit
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/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
    #
    # 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 = "/home/lmullen/todo/time-use.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}"
    end