Git reset to a specific hash version & Switch to a remote branch.

Β·

2 min read

Situation

I was working on branch b and Bob was working on branch c. Bob made some breaking changes in branch c and wanted me to test new changes.

What I did

I directly pulled that branch like git pull branch_name so what happened is that branch got merged with my branch

What was I looking for?

I was looking for fetching that specific branch c and wanted to test. And wanted to revert the merge of branches c and b. In simple words removing merge from my branch.

Solution

Fetch and switch to remote branch

To get all the remote branches to local use the following command

git fetch

Now we can switch to the remote branch c by using the following command.

git checkout <remote_branch_name>

Now we can test changes made by Bob in branch c without any conflict.

But how did I resolve the merge of the c branch with b?

First list all the past commit by using the reflog command.

git reflog

It will list all the commits with SHA. The first one indicating HEAD->branch_name is the current where we have a conflict. I found my last commit before the merge of the branch c. Find the commit where you want to revert and copy its SHA.

To revert changes to a specific commit use the reset command.

git reset --hard SHA

it will reset to the described SHA.

So this is how I resolved the problem. If you found this helpful consider giving a thumbs up πŸ‘ and share.

Thanks for reading ❀️

Β