Deploying a Previous Commit to a Live Site

Assumptions

1. Your git repository is set to automatically deploy changes on the main branch to the live site
2. You are using PHP Storm

There are various reasons why you may want to deploy a previous commit to the live site. An example would be if the latest changes introduced one or more bugs and you want to deploy the previous stable version whilst you figure out how to solve the issues.

Strategies to Deploy a Previous Commit

The most important thing is to maintain that there is only one way to deploy to the live site and that should be through changes to the main branch.

Pick the strategy that is most applicable:

  • Strategy One – If possible and applicable, roll forward:
    Rolling forwards means that we want to make the desired changes to the main branch and push them.
    – If you know the exact changes that need to be made and they are small, then rather make the changes manually and bring them in using the normal workflow / pull request.
  • Strategy Two – Revert the commit
    If you want to roll back the last one or two commits you can revert them
    – PHP Storm. menugitshow git log
    – Create a new branch to hold the changes
    – Select the commit that had the changes that need to be reverted
    – Right click on it and select revert commit
    – PHP Storm will automatically revert the changes and commit them against your current branch
    – Push the changes and create a pull request into main
  • Strategy Three – Reset to a specific commit
    This is usually the option when the revision you are wanting to deploy is older than a few commits.
    – PHP Storm. menugitshow git log
    – Create a new branch to hold the changes
    – Right click on the main branch commit that you want to revert to
    – Select reset current branch to here
    – Commit the changes
    – Push the changes
    – Push the changes and create a pull request into main