Using GIT for version control with Unity pt.3
Objective: Use the Reverting and Resetting options to place our project’s branches back to a particular time.
There might come a time where we might make a mistake in our project or have bugs that might keep the project from working correctly. Instead of resetting our project back to when we first started working on it, we can go back in time to the last time when the project worked correctly using the Revert technique.
To show how we can use the Revert technique, we went into our Dev branch and created Barriers around the area for the Player to hide behind. We need to add and commit these changes to our Dev branch to officially save them.
In GIT BASH, the first thing we want to do under our Dev branch is to use “git status” to check for any changes we have. We see there is one change modified in our SampleScene.
Next, we will add and commit these changes to the Dev branch to save them.
Now what happens if we realize that the changes we made have messed up our project or we don’t want to use them. Well, there is a way to get back to when it was working correctly which is going back to a previous commit.
Let’s use the “git log” command to show a log of all the commits made in this project.
Then, select the commit ID reference to the commit we want to go back to which in this case will be the “Create new player and player script”, copy this ID, and press the “Q” key to get out of the log command. To switch to that particular commit, use the following command: “git checkout <commit’s ID reference characters>
Once we switched over to this commit, just minimize GIT BASH and Reload the Unity editor to see that we reverted back to the previous commit made.
After checking to see if this commit is where we want to work from going forward, we can Reset this commit to be our working branch. By doing it this way we can save the newer commit just in case we might need something from it, instead of deleting it.
We’re going to switch to our Main branch using the “git checkout main” commands. Then, toggle up using the “UP” key until we show the “git checkout <commit ID>” we selected earlier. Use the “left-arrow” key to move the cursor in front of the “commit ID” and name the new branch “old-first-level” by writing the following command: “git checkout -b <new name for this branch> (commit ID reference)”
Make sure the new name for this branch doesn’t have any quotation marks around it, as this will create an error. Use “git branch” to see the new list of branches in the project, including our new branch created from our older commit named “old-first-level” as we can now switch to this as our working branch.