How to restore your project to a previous commit
Restoring a Project
Moving back in time
When we are working on a project, whether it be alone on with several collaborators, there might come a time when someone, somewhere messed up and it has already been commited. Never fear, as long as several commits have been made and pushed to the GitHub account repository, we can always revert to a previous working state.
While in the Git Bash terminal and in the current project directory, the following command will list all commits made so far:
Using the down-arrow key we can move further down the list. The information given includes a commit number specific to each commit, the author of the commit and the date and time the commit was made. Under all this is the description given to the commit. This is why it is important to document each commit with a description usning the git commit -m “description here” command.
To get out of log mode, press Q for Quit.
Now, if we still aren’t sure if the commit we see is the one we really need, there is a way to check it out before we make the decision to revert to that specific commit.
We can take the commit number, the really long one, and turn it into a branch which we can then check out in the Unity project. To do this, we would highlight the commit number we want, copy it and use the following command:
Here, the branch name is optional but recommended, otherwise the branch will be named using the commit number.
By using git checkout -b, we both create the new branch and move into it at the same time.
Once we are in that branch, if we go to the Unity project and refresh the page, we will be able to see if that is the commit we need. If it is then you can work on that branch and then commit it.
Reset master branch to a previous time
If you can’t find the commit you are looking for on the local machine, go to the GitHub repository and check out the commit list. Select the one you want and copy the commit number.
Now, back in your Git terminal type the following command:
This will place this version of the commit at the HEAD of the list. Now to update the server: