0-readme edit

git-fixing-mistakes  edit

Undoing changes


You will find most of your answers about undoing changes here: Choose-your-own-adventure walk-through of git undo options (opens in new window).

Wise words about pushing commits:

Don’t change published history

Once you git push [...] you should ideally consider those commits etched in diamond for all eternity. If you later find out that you messed up, make new commits that fix the problems (possibly by revert, possibly by patching, etc).

Yes, of course git allows you to rewrite public history, but it is problematic [...] thus it is just not best practice to do so.

Fixing mistakes
  • The last commit I pushed broke the site and it has to be fixed ASAP; aka All the things go wrong. Abort. Reverting isn't working and changes need to be made now!

    Options:

    • Use custom.css in Cascade to overwrite issue
      • Could use GitLens/source control to view the old versions of the files you changed and copy-paste the old, working version into custom.css.
    • If there is a working copy of main.css on your local computer, copy into Cascade as a temp css file and update the stylesheet link in /_theme/formats/head_base file and publish.
    • then you can take your time and go back and fix things (see next paragraph).
  • The last commit I pushed broke the site but it doesn't have to be fixed ASAP; aka I've changed files, committed them, pushed to remote and need to undo the commit.
    • Preferred. Undo changes without rewriting git history.
      (revert swaps additions and deletions made in a previous commit)
      git revert commit-id-to-revert
      or alternatively, in GitLens or Source Control, right-click on the commit you want to revert and select "Revert".
    • Alternate Preferred. Use GitLens to view the old versions of the files you changed and copy-paste the old, working version into the current files.
    • Danger. Discard all local changes and revert to previous [commit] permanently. This rewrites history. Other developers will have to redownload the repo:
      git reset --hard [commit-id-to-reset-to]
      Keep in mind that branching is the best solution when you want to retain the history of faulty development, yet start anew from certain point.
    • How to force push when having to set the css back to a much older commit.
      1. Set test and prod branches to be "unprotected" in GitLab
      2. git reset --hard [aug 27 commit hash]
        git push --force
      3. Then set test and prod branches to be "protected" in GitLab (SSH token needs branch to be protected for deploy to work)
      4. Now the repo on the creative-test server is out of sync.
        1. SSH to server
        2. Create a backup branch (using prod in this example):
          git checkout prod
          git branch prod-backup
        3. Reset all the files in prod branch to whatever the remote "origin" files are
          git fetch origin prod
          git reset --hard origin/prod
        4. Then reconnect to the GitLab branch with
          git branch --set-upstream-to=origin/prod prod
      5. Everything is now in sync.
Copy
Edit
<!-- components/0-readme/git-fixing-mistakes.php --> <div class="wm-ad-docs"> <h5>Undoing changes</h5> <p><br>You will find most of your answers about undoing changes here: <a href="https://sethrobertson.github.io/GitFixUm/fixup.html" target="_blank">Choose-your-own-adventure walk-through of git undo options</a> (opens in new window).</p> <p>Wise words about pushing commits:</p> <div class="alert" style="background-color: pink;"> <h6>Don’t change published history</h6> <p>Once you <code>git push</code> [...] you should ideally <strong>consider those commits etched in diamond for all eternity</strong>. If you later find out that you messed up, make new commits that fix the problems (possibly by revert, possibly by patching, etc).</p> </div> <p>Yes, of course git allows you to rewrite public history, but it is problematic [...] thus it is just not best practice to do so.</p> <h5>Fixing mistakes</h5> <ul> <li> <h6><span style="color: maroon;">The last commit I pushed broke the site and it has to be fixed ASAP</span>; aka All the things go wrong. Abort. Reverting isn't working and changes need to be made now!</h6> <p>Options:</p> <ul> <li>Use custom.css in Cascade to overwrite issue <ul> <li>Could use GitLens/source control to view the old versions of the files you changed and copy-paste the old, working version into custom.css.</li> </ul> </li> <li>If there is a working copy of main.css on your local computer, copy into Cascade as a temp css file and update the stylesheet link in /_theme/formats/head_base file and publish.</li> <li>then you can take your time and go back and fix things (see next paragraph).</li> </ul> </li> <li> <h6><span style="color: maroon;">The last commit I pushed broke the site but</span> it doesn't have to be fixed ASAP; aka I've changed files, committed them, pushed to remote and need to undo the commit.</h6> <ul> <li><strong style="color: #115740;">Preferred. </strong>Undo changes without rewriting git history. <BR>(<code>revert</code> swaps additions and deletions made in a previous commit)<br><code>git revert commit-id-to-revert<file></code><BR> or alternatively, in GitLens or Source Control, right-click on the commit you want to revert and select "Revert".</li> <li><strong style="color: #115740;">Alternate Preferred. </strong> Use GitLens to view the old versions of the files you changed and copy-paste the old, working version into the current files.</li> <li><strong style="color: maroon;"> Danger.</strong> Discard all local changes and revert to previous [commit] permanently. <strong style="color: maroon;">This rewrites history. Other developers will have to redownload the repo: </strong><br><code>git reset --hard [commit-id-to-reset-to]</code><BR> <em>Keep in mind that branching is the best solution when you want to retain the history of faulty development, yet start anew from certain point.</em> </li> <li> <h6 style="text-transform: none;">How to force push when having to set the css back to a much older commit.</h5> <ol> <li>Set test and prod branches to be "unprotected" in GitLab</li> <li><code> git reset --hard [aug 27 commit hash]<BR> git push --force </code></li> <li>Then set test and prod branches to be "protected" in GitLab (SSH token needs branch to be protected for deploy to work)</li> <li>Now the repo on the creative-test server is out of sync. <ol> <li>SSH to server</li> <li>Create a backup branch (using prod in this example):<BR> <code>git checkout prod<BR> git branch prod-backup</code> </li> <li>Reset all the files in prod branch to whatever the remote "origin" files are<BR> <code>git fetch origin prod<BR> git reset --hard origin/prod</code> </li> <li>Then reconnect to the GitLab branch with <BR> <code>git branch --set-upstream-to=origin/prod prod</code> </li> </ol> </li> <li>Everything is now in sync.</li> </ol> </li> </ul> </li> </ul> </div>
Copy
Copy
Edit
/* scss/0-readme/_git-fixing-mistakes.scss */