Reputation: 71
So. I have done some strange steps to get this result:
Let's say we have a branch called dev
. I'm on it at the moment.
There's another one branch called dev2
. That branch is already created remotely, but I do not have that one locally.
So, what I did is git checkout -b dev2
, which created a new branch called dev2
locally on top of the dev
branch.
After this, I just did git pull origin dev2
, so it got all the things, that was in the dev
branch.
I got a message saying that I have to fix some CONFLICTS. So I did that. Committed my fixes and pushed them. Now dev2
branch is not what it was before remotely.
Is there a way to get back my beloved dev2
branch to it's normal state?
Upvotes: 1
Views: 86
Reputation: 3120
You can check which commit on the remote you want to rollback to, then hard reset to it
git log origin/dev2 # See history on remote
From the output of this command, identify the of the commit you want to go back to (for example, 3157ee3718e180a9476bf2e5cab8e3f1e78a73b7)
Then rollback to that commit and update the remote
git checkout dev2 # Go to branch dev2
git stash # Discard your current changes
git reset --hard <hash> # Reset to the state of the hash
git push --force origin dev2 # Forcefully update the remote
Upvotes: 1
Reputation: 1323343
If another branch dev2
has been pushed by someone else, that way to get it locally is (in:
git checkout master
git branch -d dev2
git fetch
git checkout -b dev2 origin/dev2
The second command delete the 'dev2
' branch you did, because you don't have to merge anything yet: you just have to fetch and reference dev2
.
Later, you can merge dev2
to dev
, and resolve merge conflict then.
Note: this won't work if you already push (as in git push --force dev2
) back to the upstream repo.
Upvotes: 2