My GameDevHQ Journey Day 6: Revert or Reset a Branch

Nnamdi Azikiwe
2 min readDec 30, 2022

Objective: Reverting or Resetting by Branch

Let’s look at what it takes to revert our project or reset it to a previous time its history.

One of the first things we do is enter on the command line “git log” to show all the previous commits we made on the main branch such as creating a new cube, adding inventory and even creating the new Unity project.

A log of all the commits made on the main branch.

We have a variety of options to restoring a project. It is never an option to reset a project and then lose all the data previously associated with it. Committing the new change and allowing people to download it causing them to lose their work is not desirable. This requires us to follow a workflow ensuring we preserve our revision history. One thing we can do is treat revisions like branches.

Will we create a branch back to where we created a new cube?

We think the commit where we “created new cube” is the point we want to rollback. So after pressing the “q” key to get out of the log screen we enter on the command line “git checkout ad6961a89eb4a2e6af6b45ebf2517e82de831866.” That represents the hashcode where we created a new cube. The command produces information about our options. Essentially we can either create a new branch or undo the operation. Before we do either, we go into Unity and verify it is the correct location in our history where we want to rollback.

“git checkout ad6961a89eb4a2e6af6b45ebf2517e82de831866" puts our branch in a “detached head state.”

In Unity we see the challenge script is the only one in the Assets folder. Git also, tells us we are in a ‘detached HEAD’ state. At this point, were it necessary, we could commit our freshly rolled back Unity project as if the changes adding the dev script and inventory never happened.

“git checkout main” puts us back on the main branch.

Entering “git checkout main” switches us back to the main branch. While in the main branch we can use “git checkout -b old-project-state ad6961a89eb4a2e6af6b45ebf2517e82de831866” to create a new branch.

--

--

Nnamdi Azikiwe

Join me on a 90+ day journey in Game Development with Unity 3D using C#.