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:

Gt log command
Git log

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.

log file

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:

Make branch from commit number

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.

creating a git branch from commit number

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.

Copying commit number from GitHub repository

Now, back in your Git terminal type the following command:

reseting master

This will place this version of the commit at the HEAD of the list. Now to update the server:

Forcing master to update to specific commit

NOTE: Be VERY careful with this as it can erase all work done by others as it reverts to that specific point of the project. Everything that had been done after that point is lost.




Poultry Scientist by profession, Computer Scientist at heart. After many years in the poultry business, I have decided to give my passion for technology a shot.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Why Mobile App Development Has Become a Need of Hour For Immigration Business?

How to run SSH terminal commands from iPhone using Apple Shortcuts SSH

The SDDCbox Project — Part #2 — Testing the Waters

Apple's Mac Pro

下载和观看 鬼灭之刃剧场版:无限列车篇 2020 (Demon Slayer: Kimetsu no Yaiba) 完整版本 HD/BluRay

Launch EC2 instance, create EBS volume, send sms, mail, whatsapp and telegram message…

Lifehacking: The Right Way to Ask for Help (Tech Support Series Part 1)

Visualizing Repetitions in String using Python and Matplotlib

Search In a Binary Search Tree 🌳| Daily LeetCode Challenge | Day 14 | Coding Interview

LeetCode 700 | LeetCode daily challenge Day 14 Solution

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
Marc Frappier

Marc Frappier

Poultry Scientist by profession, Computer Scientist at heart. After many years in the poultry business, I have decided to give my passion for technology a shot.

More from Medium

My Experience CodeText Editors#1#VSCode,Vim,Neovim,Atom

Using Layered Lit to mix Texture Maps

Initializing A Git Repository in Unity

Making WebSocket connection using fastify: