Use git to easily make third party module patches

[This post originally showed up on use.Perl. Yanick subsequently released Git::CPAN::Patch]

In the olden days, to make a patch to a module, you had to have the original, untouched file and a copy that you modified. You’d then use diff to compare the two files.

At the Pittsburgh Perl Workshop, Ricardo was asking how to do some odd thing in git. Instead of anyone answering his question, everyone asked what he was doing. It turns out he was patching someone’s module and making it a git repo while he worked. The process is really handy:

  • Download module distribution and unpack it
  • Make it a git archive with git init
  • Add the initial content to the index with git add .
  • Commit the initial content with git commit -m “* Version 1.23 from CPAN”
  • work, work, work
  • Generate your patch with git format-patch –stdout -1
  • And Bob’s your uncle

There are other ways that you can do this, and you can change around the process in git. I like that git is lightweight enough to make it actually useful for everyday work.

Leave a Reply

Your email address will not be published. Required fields are marked *