In some cases, running composer update could mean several dependency updates, as well as even database changes. Unfortunately, you won’t always get the chance to completely test and deploy these updates before having to continue on with other tasks.
On the other hand, saving these updates to a separate branch, or stashing them in a git stash, might cause several errors on your local site.
Here is a procedure I use to keep my short-term changes separate from my local update.
First, checkout a new branch:
Then commit all your updates (this commit will not get pushed):
Next, do your short-term development and changes, then commit those:
At this point, your local history will look something like:
If you're like me and still have other uncommitted changes that are a work in progress, you can safely set those aside as well:
Now, it's time to deploy to master:
There are a few shortcuts for cherry-picking commits. If you want to just cherry pick the last one from a branch, it’s as simple as:
If you want to cherry-pick the last two:
Note that using the branch name itself is the equivalent of saying 'the most recent hash of this branch.'
Therefore "upgrades~1" is the equivalent of saying "the second to last hash of this branch."
If you use the exact hashes, and you give a range to cherry-pick, be sure that your first hash includes a ~, meaning “grab from this hash to the next hash, but also include this hash."
Now, do a git pull to grab the latest, and then a get push.
The last step is to make sure that your “upgrades” branch will be as clean and readable as possible. What we do is rebase master to re-order your commits.
Now your upgrades history will look something like:
To bring back those previously uncommitted changes, just run:
And you're done! Repeat this process however many times you may need until you can safely push your composer upgrades.
Code
Drupal
Drupal 8
Process
git checkout -b upgrades
git commit -m 'local updates: do not push'
git commit -m 'SITE-123: Fixes issue with user save' git commit -m 'SITE-124: Adds new form for user signup'
commit 393aba6a826b9155eb1b8b60e6cd03fbcf2bcf7f (HEAD -> upgrades) Author: Alan <alan@atendesigngroup.com> Date: Thu Jul 12 13:34:52 2018 -0600 SITE-124: Adds new form for user signup commit d357a71b17c5a631e83452f671a32d02a05c7485 Author: Alan <alan@atendesigngroup.com> Date: Thu Jul 12 10:40:04 2018 -0600 SITE-123: Fixes issue with user save commit d5dca1b09f318113aad3fcbf65e99a460a68ec23 Author: Alan <alan@atendesigngroup.com> Date: Tue Jun 5 16:39:19 2018 +0200 local updates: do not push
git stash
git checkout master
git cherry-pick upgrades
git cherry-pick upgrades~1..upgrades
git pull -r origin master
git push origin master
git checkout upgrades git rebase master
commit d5dca1b09f318113aad3fcbf65e99a460a68ec23 Author: Alan <alan@atendesigngroup.com> Date: Tue Jun 5 16:39:19 2018 +0200 local updates: do not push commit 393aba6a826b9155eb1b8b60e6cd03fbcf2bcf7f (HEAD -> upgrades) Author: Alan <alan@atendesigngroup.com> Date: Thu Jul 12 13:34:52 2018 -0600 SITE-124: Adds new form for user signup commit d357a71b17c5a631e83452f671a32d02a05c7485 Author: Alan <alan@atendesigngroup.com> Date: Thu Jul 12 10:40:04 2018 -0600 SITE-123: Fixes issue with user save [other changes that came from master remote]
git stash pop
Skip to footer
Comments