Skip to content

Commit

Permalink
Add tabs for IC vs Non-IC when resetting dev to live
Browse files Browse the repository at this point in the history
  • Loading branch information
rachelwhitton committed Jan 23, 2025
1 parent 05223db commit ed6d790
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
29 changes: 29 additions & 0 deletions source/content/guides/git/05-undo-commits.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ cms: [drupal, wordpress]
audience: [development]
product: [--]
integration: [--]
reviewed: "2025-01-23"
---

Git makes it easy to reverse commits pushed to the Pantheon Dev environment.
Expand Down Expand Up @@ -174,6 +175,10 @@ You can revert a past commit that has been pushed to your Test or Live environme
You can reset your Dev environment history to match the current state of your Live environment using [Terminus](/terminus). The method in this section is destructive and should be used with caution. It does not clone the Live environment's database or files down to Dev. However, it does reset the Dev environment's codebase.
<TabList>
<Tab title="All others" id="all-others" active={true}>
1. Identify the most recent commit deployed to Live.
1. Run the command below to overwrite the history on Dev's codebase to reflect Live (replace `<site>` with your site's name):
Expand All @@ -183,6 +188,30 @@ You can reset your Dev environment history to match the current state of your Li
git push origin master -f
```
</Tab>
<Tab title="Integrated Composer" id="integrated-composer">
<Alert title="Note" type="info">
We've adjusted the following steps for [Integrated Composer sites](/guides/integrated-composer), so that you reset history to the **second** to last commit hash on the Live environment, rather than the first - to avoid resetting dev's history to a build artifact.
</Alert>
1. Identify the **second** most recent commit deployed to Live.
1. Run the command below to overwrite the history on Dev's codebase to reflect Live (replace `<site>` with your site's name):
```bash{promptUser: user}
git reset --hard `terminus env:code-log <site>.live --format=string | grep -m2 'live' | tail -n 1 | cut -f 4`
git push origin master -f
```
</Tab>
</TabList>
## What if Dev Is Behind Test and Live?
This happens if you **reset** Dev to an earlier commit, rather than using **revert**. You must make a commit on Dev to re-sync the environments. This will also get the commit history between the environments to match. The commit you use can be trivial, such as a space or extra line added to a comment within a file. You'll see the commit available for deployment on Test, and then on Live after you commit the change.
Expand Down
69 changes: 69 additions & 0 deletions source/content/terminus/03-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cms: [drupal, wordpress]
audience: [development]
product: [terminus]
integration: [--]
reviewed: "2025-01-23"
---

This section provides information on how to apply updates, deploy code, switch upstreams, and install Drush and WP-CLI with Terminus, as well as information on command structure and automatic site and environment detection.
Expand Down Expand Up @@ -281,6 +282,11 @@ There are a few scenarios where it may be useful to reset your Dev environment (

- The Dev environment has been seriously corrupted and you would like to cleanly reset it to Live.


<TabList>

<Tab title="All others" id="all-others" active={true}>

Follow the steps below to reset Dev to Live.

1. Clone the site's codebase to your local machine if you have not done so already (replace `awesome-site` with your site name):
Expand Down Expand Up @@ -330,6 +336,69 @@ Follow the steps below to reset Dev to Live.

The Site Dashboard will open when the reset procedure completes.

</Tab>

<Tab title="Integrated Composer" id="integrated-composer">

Follow the steps below to reset Dev to Live.

<Alert title="Note" type="info">

We've adjusted the following script for [Integrated Composer sites](/guides/integrated-composer), so that you reset history to the **second** to last commit hash on the Live environment, rather than the most recent - to avoid resetting history to a build artifact.

</Alert>

1. Clone the site's codebase to your local machine if you have not done so already (replace `awesome-site` with your site name):

```bash{promptUser: user}
terminus connection:info awesome-site.dev --fields='Git Command' --format=string
```

1. Automate the procedure for resetting Dev to Live by downloading the following bash script:

<Download file="ic-reset-dev-to-live.sh" />

```bash
#!/bin/bash

#Authenticate Terminus
terminus auth:login

#Provide the target site name (e.g. your-awesome-site)
echo 'Provide the site name (e.g. your-awesome-site), then press [ENTER] to reset the Dev environment to Live:';
read SITE;

#Set the Dev environment's connection mode to Git
echo "Making sure the environment's connection mode is set to Git...";
terminus connection:set $SITE.dev git

#Identify the second most recent commit deployed to Live and overwrite history on Dev's codebase to reflect Live
echo "Rewriting history on the Dev environment's codebase...";
git reset --hard `terminus env:code-log $SITE.live --format=string | grep -m2 'live' | tail -n 1 | cut -f 4`

#Force push to Pantheon to rewrite history on Dev and reset codebase to Live
git push origin master -f

#Clone database and files from Live into Dev
echo "Importing database and files from Live into Dev...";
terminus env:clone-content $SITE.live dev

#Open the Dev environment on the Site Dashboard
terminus dashboard:view $SITE.dev
```

1. Execute the script from the command line within the root directory of your site's codebase:

```bash{promptUser: user}
sh /PATH/TO/SCRIPT/reset-dev-to-live.sh
```

The Site Dashboard will open when the reset procedure completes.

</Tab>

</TabList>

## Switch Upstreams

Every site has an assigned upstream to deliver [one-click updates](/core-updates) in the Pantheon Site Dashboard. Terminus can be used to manage this site-level configuration. There are a few scenarios where it may be useful to change a site's upstream:
Expand Down
26 changes: 26 additions & 0 deletions source/scripts/ic-reset-dev-to-live.sh.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

#Authenticate Terminus
terminus auth:login

#Provide the target site name (e.g. your-awesome-site)
echo 'Provide the site name (e.g. your-awesome-site), then press [ENTER] to reset the Dev environment to Live:';
read SITE;

#Set the Dev environment's connection mode to Git
echo "Making sure the environment's connection mode is set to Git...";
terminus connection:set $SITE.dev git

#Identify the second most recent commit deployed to Live and overwrite history on Dev's codebase to reflect Live
echo "Rewriting history on the Dev environment's codebase...";
git reset --hard `terminus env:code-log $SITE.live --format=string | grep -m2 'live' | tail -n 1 | cut -f 4`

#Force push to Pantheon to rewrite history on Dev and reset codebase to Live
git push origin master -f

#Clone database and files from Live into Dev
echo "Importing database and files from Live into Dev...";
terminus env:clone-content $SITE.live dev

#Open the Dev environment on the Site Dashboard
terminus dashboard:view $SITE.dev

0 comments on commit ed6d790

Please sign in to comment.