My deployment process for our Drupal projects normally involves recreating feature based modules via drush fu module_name -y
. A bad part of this is having tons of changes exported to code at one time. I try to make every git commit reference a specific issue number. This is where git add -p [filename]
comes in handy.
Let's say I have a module that uses Features to track a custom view that lists users for my Drupal site. The customer has submitted two new tickets of feature requests. One is to change a column label (ticket #100), and the other is to sort the users by last login date (ticket #101).
I've now made the changes to the view and updated the featureized module via drush fu example_module -y
.
The resulting git diff
is:
I want the changes to be committed in 2 parts, one for each ticket number. I can accomplish by running:
git add -p example_module.views_default.inc
Git will show the changes and provide us a series of options: Stage this hunk [y,n,q,a,d,/,s,e,?]
. Because the changes are so close together, Git thinks it is one big hunk. We want to "split" these changes up into smaller hunks, so we'll type s
at the prompt.
Git will then break the change into smaller hunks and ask what to do with each. We'll press y
to stage the first hunk that is related to the label change. We'll then exclude the last hunk that is specific to the sorting change by pressing n
at the prompt.
Now we can commit the staged changes.
git commit -m "Changing field label. Issue: #100"
The remaining alterations are related to the sorting change we just skipped, so we can just add and commit.
git add -A git commit -m "Changing sort parameters. Issue: #101"
Software engineer by profession, embedded systems tinkerer, husband, father, fantasy novel devourer, wine lush, beer and cheese connoisseur