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 How to check if radio button is checked or not using JavaScript? #2 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#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 #Jan 14 How to display a student’s individual transcript in Colleague? #Jan 11 How to install PuTTY on a MacOS?
You might also like these
What are Null Sessions?MiscellaneousSolution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software”MiscellaneousHow to add Date and Time picker in HTML and get the values using JavaScript?HTMLThe 7 Security Objectives of Any Organization for IT and Network SecurityMiscellaneousHow to show confirmation alerts with OK and cancel buttons using Swift 5?Swiftaddcslashes() and addslashes() String Functions in PHPPHP