Git reverting or resetting by branch
What happens if you reset a project, commit the change and push it to the server? Well, now the new commit will become the HEAD of the project. Which means any member of your team who downloads this repository will lose valuable data from the previous workflow, and have to redo everything lost all over again.
We can revert to an old commit which means to undo changes committed, but the rest of the project stays the same. Or, we can reset a commit which means we will go back in time, drop all changes made after the particular commit picked, and work from there.
Start by using “git log” command to see all of our commits. Pick the commit that will take you to the previous data the we will work from before the problem.
Ex. (commit f288ff90f197756e53ea4b245afa9da8ec5a3ef3
Author: Name <your e-mail>
Date: Fri Apr 30 02:24:21 2021 -0400)
This command will treat the commit as a branch, and allow us to go back into the Unity editor to see if this state is where we need to pick up from with this commit.
- git checkout f288ff90f197756e53ea4b245afa9da8ec5a3ef3
Once we decide if this commit is where we want to work from, use the following command to turn the commit into a branch.
- git checkout -b old-project-state f288ff90f1…
The commit will now have a new branch name called “old-project-state”. We can now work off this old build, and if we need to go back to the master build there will be a reference to it.
If you want to reset to a particular commit, all commits will be lost that came after the commit you decided to reset to. Plus, the HEAD will now be at that process. The command as follows:
- git reset — hard f288ff90f1…
To push the reset to the server, use the following command:
- git push — force origin master
When you go to the Github server, the changes should be visible that you reset to. This reset process can be dangerous, and should only be used on your local machine branch. Consider branching any changes needed to be made and keep your work just in case, compared to reset and not being able to go back to work committed that was done after.