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.

Barrier objects added to scene under the Dev branch.

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.

Used git status to check for any changes that need to be committed.

Next, we will add and commit these changes to the Dev branch to save them.

Changes are added and committed to the Dev branch.

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.

Used git log to see the past commits.

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.

Reverting back to an old commit as a branch.

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.

Old commit turned into a new branch to be used as a reset branch.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store