Version Control : Rolling Back Deployments

Version Control : Rolling Back Deployments

·

3 min read

Table of contents

Rolling back a deployment

Rolling back a deployment means reversing the changes that were made during deployment by reverting the system to a previous state. This might involve undoing code changes, rolling back database updates, or restoring configuration files to their previous versions.

Rolling back a deployment is usually done when there are issues with the new code or configuration, or when it is discovered that the deployment has caused unintended consequences. The goal is to restore the system to a known good state as quickly as possible so that it can continue to function correctly.

There are different ways to roll back a deployment depending on the tools and processes being used. For example, you might use version control tools to revert code changes or use a database backup to restore the state of the database. Some DevOps tools also provide functionality specifically designed for rolling back deployments, such as blue-green deployment or canary deployment.

You can also use Git/GitHub to roll back your changes depending on the specific circumstances and the tools you are using. Here are some examples:

  1. Revert a commit:

    If you have deployed code changes by pushing a commit to a Git repository, you can use the git revert command to undo the changes introduced by that commit. This creates a new commit that undoes the changes made in the original commit. For example:

    git revert

    This will revert the changes made in the commit with the specified hash, and create a new commit that contains the reversed changes.

  2. Reset to a previous commit:

    If you want to completely remove a commit and all the changes made in it, you can use the git reset command. This will move the current branch pointer to the specified commit and discard any commits made after it;

    git reset --hard

    This will reset the current branch to the commit with the specified hash, discarding any commits made after it. Be careful with this command, as it permanently discards commits and cannot be undone.

  3. Create a new branch and cherry-pick commits:

    If you want to selectively revert some commits but keep others, you can create a new branch from the commit before the changes you want to revert, and cherry-pick the commits you want to keep onto the new branch;

    git checkout -b new-branch

    git cherry-pick ...

    This will create a new branch based on the commit with the specified hash and cherry-pick the specified commits onto the new branch. This allows you to selectively revert some commits while keeping others.

These are just a few examples of how you can roll back a deployment using Git or GitHub. The specific steps will depend on the tools and processes you are using, as well as the specific changes you want to revert.