Yogesh Chauhan's Blog

How to undo Git Commits on Pantheon?

in Miscellaneous on December 21, 2021

There are times when things don’t go right after commiting a small change you make. Sometimes the updates from Drupal and WordPress or even a plugin update breaks the site. In those cases, all you want to do is just remove those changes you just made.

Let’s go through the revert process of a Git commit before and after pushing to Pantheon.

I assume you have git and Pantheon local environment setup done already on your local machine.

If not, use these Pantheon articles to do so.

Local Development for Pantheon

Starting With Git for Pantheon

Delete the Latest Commit from Local Machine

When you work with Pantheon environment, you develop sites locally and then push changes to the dev, test and live versions.

If you’ve made changes to your local site but have not yet pushed those changes to your dev site, you can use this command to revert those changes back.

Remember that it’ll delete all the recent changes you made in your latest local commit.

git reset --hard HEAD~1

Delete the Latest Commit from the Dev Environment

This will remove the latest commit from the dev environment.

git reset --hard HEAD~1
git push --force origin master

This will reverse the last commit and leave the history:

git revert HEAD --no-edit
git push origin master

Reset Dev Environment to Live

We can use terminus to match the state of dev environment with the state of the live environment.

It’ll only copy the code from live and not the files or database. You need to import files and db using another way.

In the code below, replace with your site’s name.

git reset --hard `terminus env:code-log .live --format=string | grep -m1 'live' | cut -f 4`
git push origin master -f

Credit: Undo Git Commits

Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
How to detect if browser supports WebP format on server side PHP script?PHPHow to display a student’s individual transcript in Colleague?ColleagueHow to use a Subquery to Insert Multiple Rows in SQL Table?SQL/MySQLHow to avoid element shift on border change while hovering in CSS?CSSHow JavaScript classes allows us to do less typing (syntactic sugar)?JavaScriptLearn to Make a Simple Contact Us Form using PHP and PDO-MySQLPHP