How To “Go Back” To A Previous Commit In BitBucket/GitHub Repository

vorfra
2 min readJul 19, 2021
Photo by Joshua Aragon on Unsplash

By using git reset, you are creating a new commit which rolls back to a previous commit. On the BitBucket/GitHub side, it means the HEAD pointer will point at the new commit that we will indicate with the git reset.

For example:

Commits A and B are working commits, but commits C and D are bad commits. It’d be better if commits C and D were no longer in the repository because they have broken the development environment pipeline. To use commit B, it’s possible to “go back” and drop commits C and D.

Currently, HEAD is pointing to commit D, 5lk4er, we need to point the HEAD to commit B, a0fvf8.

You can change the pointer by using the git reset command:

git reset --hard a0fvf8 //give the commit number which will now be the new HEAD

git reset: is the command

— hard: is the flag option

a0fvf8: is the commit number available on BitBucket/GitHub’s repository

After executing the above command, the HEAD will point to commit B.

However, the change is currently only in the local directory of your personal computer. It hasn’t been pushed into the BitBucket/GitHub repository. In order to push the changes from your…

--

--