Skip to content

Instantly share code, notes, and snippets.

@youpy
Created December 13, 2009 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youpy/255400 to your computer and use it in GitHub Desktop.
Save youpy/255400 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# usage: git-commit-as github-username -m 'commit message'
require 'open-uri'
require 'rexml/document'
def main
username = ARGV.shift
userid = userid(username)
system('git', 'commit', *ARGV)
system(<<COMMAND)
git filter-branch -f --commit-filter '
GIT_AUTHOR_NAME="#{username}"
GIT_AUTHOR_EMAIL="#{userid}"
GIT_COMMITTER_NAME="#{username}"
GIT_COMMITTER_EMAIL="#{userid}"
git commit-tree "$@"
' HEAD^..HEAD
COMMAND
end
def userid(username)
doc = REXML::Document.new(open('http://github.com/api/v2/xml/user/show/' + username).read)
doc.elements['/user/id'].get_text
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment