Home
  • English
  • עברית
  • Home
  • Portfolio
  • Blog
  • Services
  • About us
  • Contact

Using git to write patches

Submitted by Amitaibu on Sun, 12/27/2009 - 12:01
— Tagged as
  • Drupal-planet

Drupal is using CVS for version controlling core and contrib modules. CVS has diffing options, but it becomes annoying when you try adding or deleting new files. Here's an example of how to use git to patch a contrib module - Organic groups.

  1. In OG's project page click on the CVS instructions and select the version you want to patch.
    cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -d og-DRUPAL-6--2 -r DRUPAL-6--2 contributions/modules/og/
  2. Go inside the directory you just checked out from CVS.
    cd og-DRUPAL-6--2
  3. Make the folder and all sub-folder a git repository, and add all the files.
    git init
    git add .
    git commit -m "Initial commit of the Organic groups module."
  4. No we have a master branch with the original module. We can create a new git branch and work on this new branch - edit files, move files around, create new directories, etc'.
    git checkout -b new-branch
  5. The new-branch is now the active branch. Do some changes to code, and commit them.
    git commit -a -m "A meaningful commit description."
  6. In order to create a diff file, we need to switch back to the master branch, and create a diff against our new-branch. Note that we use the --no-prefix command to follow the patch creation standard of Drupal.
    git checkout master
    git diff --no-prefix master new-branch > [issue-id]-[patch description]-[comment number].patch
  7. We can delete the temporary branch.
    git branch -D new-branch

If you want to work only with git, and skip the CVS part, have a look at git.drupalfr.org.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><blockquote>
  • Lines and paragraphs break automatically.
  • Pairs of<blockquote> tags will be styled as a block that indicates a quotation.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

Gizra | Brener 5, Tel-Aviv 63826 Israel | +972-527-587-697 | info@gizra.com