Using GIT for version control with Unity pt.4

Rhett Haynes
4 min readMay 25, 2022

Objective: Showing the effects of using the hard reset on the Main branch, and why this technique should be used carefully or avoided at all cost in your project.

Previously we used a soft reset by taking past commits, turning the one chosen into a branch with a new name using their commit ID reference code, and merging this new branch with the Main branch.

Now we’re going to use a different way to reset a branch by using a Hard Reset. To begin, switch to the Main branch, and use the “git log” command to show the log of all commits created. From here we can choose which commit we want to reset our project back to. In this case, we’re going to use the “Created a version control demo for practice” commit as our reset point.

Checked for past commits to use for a hard reset.

Another way to retrieve the commit we’re going to use is to go in GitHub to the project’s repository. Then, switch to the Main branch if it’s not selected already.

Selecting the Main branch inside GitHub.

Head over to the commits section where we have 3 commits submitted to the Main branch.

Clicked on the 3 commits under the Main branch.

From the list of commits, we chose the 1st commit entered for our project.

First commit entered was selected to be our reset point.

Go to the commit ID reference code, and click on it to open the commit.

Clicked on the commit ID reference.

At this point, we will select the commit ID reference code to use in GIT BASH.

Selected the commit ID reference code.

Copy this commit ID and go back to GIT BASH.

Copied the commit ID reference code.

Inside of GIT BASH, we’re going to reset the local Main branch by using “git reset — hard <commit ID reference>” commands. When the hard reset is finished, notice the HEAD is now located at the commit ID reference code’s location. Go to the Unity editor, click the RELOAD button, and notice the scene reverts back to the original commit entered which for us is an empty scene.

We’re now satisfied with restarting our project from this point in time. To make this reset complete, let’s use “git push — force origin main” to push this local reset to our Main branch repository.

Local branch Main pushed to the Main branch repository to complete the resetting.

Back in GitHub, look at the Main branch commits and notice that the branch is now set to the 1st commit entered. If you also notice, the other commits that were entered under the Main branch have been deleted. Therefore, there is no way to go back to another commit once we use the Hard Reset commands on the Main branch.

Unless, we have a backup branch which in this case will be our Dev branch. If we need to go back to another point in time in our project, we must use a commit from the Dev branch to revert the project back to where we want to work from.

Main branch reset to 1st commit, and we have the Dev branch to revert back just in case.

Make sure you really need to use this Hard Reset on your Main branch because once it’s done and pushed into the remote repository, you and your team will end up working from this point in time and losing valuable work done already. Use a Soft Reset with changing commits into branches and save the other branch that we want to reset as a backup just in case.

--

--