And what if you want to look back on your project?

Resetting your commits by branch and resetting whole project


You can have all kinds of branches and that’s practical! And no I’m not talking about those branches you find from nature :D

You have your master branch, then you can have a dev branch and a branch for inventory and pickable items for example! :)
If these areas in game development have their own branch, it’s much easier to control the updates.

Commands for branches

To see your available branches you can write
git branch

See available branches

This was something that I wrote already in my last article, where I wrote about pulling, committing, and pushing. You can check it from here!

And to create a new branch you use
git branch dev

This means you will create a branch named dev

And you gotta navigate in branches too, yes? There is a way to do this!
There are two options you can use!
git checkout dev
git switch dev

Switching from quest to dev branch

Resetting by branch

So what if you want to go back in time? Back to maybe to the third last commit you made? And not to mess up your previous commit.

This is easy to do with just creating a new branch with commit hash code. And we can do this by writing

git checkout -b old-project-state hash code

The commit hash code will be the one that we want to go back to.
Now there is a completely new branch and you are not harming the ones you have already! :)

Reset project to older state (Be careful when using this!)

Before we reset by branch but we can reset our master branch back to an older state.

This we can do by writing

git reset --hard commit hash code
This will reset our local to this commit

Then we need to force this change to our server by writing
git push --force origin master

Thank you for watching my journey learning Git! There will be more studying but not sure if I will make new articles about it.

We did it! :) Now, go take a break and enjoy a cup of good coffee or tea or water! I will see you next time when I write about 2D Game Development!
Can’t wait…! :)

Photo by Demi DeHerrera on Unsplash

From the beautiful snowy country with a touch of "good" humor? Inspired Unity Developer to learn more.