Skip to content

Instantly share code, notes, and snippets.

@mconnell
Created October 10, 2013 09:31
Show Gist options
  • Save mconnell/6915616 to your computer and use it in GitHub Desktop.
Save mconnell/6915616 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
##
# script to amend a commit which should be been created with the previous script
##
commit_message = `git log --format=%B -1`.strip
branch_name = `git rev-parse --abbrev-ref HEAD`.strip
matches = branch_name.match (/\w\-(\d+)\Z/i)
pivotal_story_id = matches ? matches[-1] : nil
commit_message = "[##{pivotal_story_id}] #{commit_message}" if pivotal_story_id
`git commit --amend -m "#{commit_message}"`
#!/usr/bin/env ruby
##
# script to prepend a commit with [#story-id] if the branch is suffixed with the story-id
##
commit_message = ARGV[0]
branch_name = `git rev-parse --abbrev-ref HEAD`.strip
matches = branch_name.match (/\w\-(\d+)\Z/i)
pivotal_story_id = matches ? matches[-1] : nil
commit_message = "[##{pivotal_story_id}] #{commit_message}" if pivotal_story_id
`git commit -m "#{commit_message}"`
@mconnell
Copy link
Author

To explain this script:

Working on a codebase where branches are labeled "some_branch_name-123435" and 12345 is a pivotal story id.

These scripts allow me to write a commit message as I normally would, and it will then prefix each commit message so I end up with "[#12345] original comment here".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment