Reputation: 29
A colleague of mine somehow pushed his HEAD revision of a release branch my team is working on to our main development branch. (This would be 145 commits improperly pushed)
I want to keep our commit history clean so I am toying with the idea if I should do anything, or just create a new Development branch to begin working on.
I cannot simply do a
git revert <last-trusted-sha>..HEAD
Because there are multiple merges on the branch (From when we do a pull request and Git creates a merge remote_currentbranch to currentbranch).
Is there any way to resolve this easily? Or do I just go commit by commit until it is corrected?
Thanks
Upvotes: 1
Views: 83
Reputation: 8345
This should be quite easy to fix technically:
git branch develop THEHASH -f
git push origin develop -f
Normally you would not do something like this out of respect for your colleagues. But in this case, everything is broken anyways already, so you might as well.
To find the correct commit 145 steps back, git reflog
might be of help, unless you can spot it easily using git log
.
Upvotes: 0
Reputation: 38106
To recover development
branch, you can use below commands:
git checkout development
git reset --hard HEAD~145
git push -f
Or if you know the last commit sha-1 value on the development
branch before commits on the release
branch were pushed to the development
branch, you can also use git reset --hard <last commit>
to replace the command git reset --hard HEAD~145
. Then the development
branch would be recovered.
Upvotes: 2