Tech Tips
Product Features

Amend, Revert, Checkout, Restore: The Many Tools to Recover Prior Versions with Copia

Published on
October 25, 2022

One of the core benefits of Copia’s Git-based Version Control is that it allows users to easily access every prior version of their PLC files at any time.

To this end, Copia supports several powerful tools with their own unique benefits, limitations and use cases; let’s take a look at what they are, what they can do, and when someone might prefer one over another.


Amending allows users to modify a commit before pushing

After committing, but before pushing, a set of changes to your repository, you can amend the most recent commit. This allows you to change the commit message, description, and file contents in your commit before re-committing, and pushing those changes to the remote repository.

This allows you to actually change the contents of a commit, rather than committing new changes on top of old ones, however can only be performed on the most recent commit, and only if the commit only exists in the local repository; as such, Amending a commit is most helpful when you notice a mistake in your PLC logic, or a typo in your commit message – or, for example, leaving out the Jira issue key if you’re using Copia’s Jira integration – before pushing those changes to your remote repository.


Reverting creates a new commit to reverse the changes from the previous commit

Copia always allows you to revert the most recent commit to your repository, even if the commit has been pushed to the remote repository.  Reverting creates a new commit, undoing the changes in the most recent commit; this ensures that the reverted commit remains unchanged in the commit history, and indicates in the new commit that the prior commit had been reverted.  

Like Amending, Reverting can only be performed on the most recent commit with Copia, however a commit can still be reverted if it is already on the remote repository. This is most helpful when you notice an issue in the most recent commit you or any teammate has made which must be undone, and allows you to record publicly that this has been done.


Checking a Commit out puts Copia's Desktop App onto a temporary branch

A Commit Checkout allows you to recover the contents of any previous commit; when you check out a commit, your repository is temporarily set back to the state it was in when that commit was made, in what’s known as a ‘Detached Head’ state. This is a temporary branch at the selected commit, meaning, you will only see the commit history leading up to the selected commit, and you will be unable to push any commits you make in this state.  Importantly, this also means that any commits you make to your repository while in this state will be erased when you move back onto a named branch.  However, you can create a permanent branch from a ‘Detached Head’ state, which will allow you to return to this version simply by switching branches, and will allow you to commit changes normally to your newly created branch.  In your repository history, the new branch will branch off from your selected commit, making it easy to see which version was used to create the new branch.

Unlike Amend and Revert, a Checkout can be performed on any commit from any branch, giving much more power to retrieve prior versions of your PLC files; however, it requires that a new branch be created to make any new commits to the retrieved version. As such, it is most useful when making new changes to legacy code, or temporarily retrieving an older version of your repository to recommission a  downed machine.


Restoring from a commit changes files directly, without altering the Commit History

Restoring from a Commit functions like a Commit Checkout, with a few key differences.  Restoring sets the contents of your repository to the state they were in when the restored commit was made; however, it does not place you in a ‘Detached Head’ state, instead keeping you in whichever branch you were already in.  Instead, it shows the old version as ‘new’ changes, and allows you to freely modify and commit these changes onto your current branch.

Restoring from a Commit is most helpful when undoing several recent commits onto your main code branch, or, generally, when you want to restore any prior version of your repository’s contents as the most recent commit.

Special Mention: Undo

The "Undo" button can remove Commits before pushing, but they cannot be recovered

For commits made mistakenly, users may wish to undo a commit completely, rather than amend the commit.  Copia provides the option to undo commits made, which haven't yet been pushed to the remote repository. Undoing a commit doesn't change the files currently in your repository, but caution should be taken, as undoing a commit removes it from the repository completely, after which it can't be checked out or restored.