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
command-line commands commit development environment git pantheon server