5

What's the best way to update a module and commit with git?

Currently I'd use drush pm-updatecode then inspect with git status. The problem then is there are many files that have changed, been added or been deleted. Then performing an add or rm on the right files seems a bit cumbersome.

Would it be better to first do rm on the module, commit, then drush dl, add, commit?

7

git add -A is the simple answer you are looking for. It will add all of the files anywhere inside the current working directory, including any new files that were provided or removed pm-updatecode. (Note: git add . behaves similarly to git add -A, except that it will not include removed files in the commit.)

There is one inconvenience with git add -A, though, and that is that if you have any stray files in the way, they will be added to the repository as well (obviously enough). You can get around this problem by listing the files that should never be committed in a .gitignore file, or simply use git reset HEAD unwantedfile prior to git commit, as recommended by git status.

drush will manage this for you with the --version-control=svn option, but as you may surmise, this is only useful when you project is checked in to svn. As of yet, no one has written --version-control=git. This was discussed in http://drupal.org/node/797190, but closed "won't implement". There are some other good git commands to try in that thread as well.

1

If you are updating the Views module for example, you can do the following:

drush up views
git add /sites/all/modules/views
git commit -m 'views update'

This way only the changes in your views folder will be added to staging before commit.

  • 2
    This is essentially correct, but will miss files removed in the update. – greg_1_anderson Aug 21 '12 at 5:51
  • So the second line should be git add -A /sites/all/modules/views ? – Nic May 9 '16 at 10:05
-1
git rm -r module
drush dl module
git add module
git commit -m "Upgrading module"
git push origin master
  • Please explain your steps in greater detail. – Scott Joudry Nov 2 '13 at 0:00
  • This would pollute the git database in the case where most files where unchanged – Nic May 9 '16 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.