Reputation: 6471
I have 2 remote branchs which are dev and master.
I always develop in dev branch and merge the change to master branch.
But I found I have accidentally use master branch to develop and then commit and push to the remote.
Is there any way to revert it, like cancelling the last commit without making new history?
I am using source tree
Upvotes: 3
Views: 1268
Reputation: 22047
(CLI solution - but a SourceTree solution is still welcome)
Since you work alone on the repo without banch permissions scheme blocking you from pushing, your only problem is to find on which commit was master
before your last push.
You can find that simply from your git log --oneline master
output if you just committed a few times. Find the last merge from dev
, note that commit hash, let's call it <oldMasterHash>
.
Then just do
# move dev where master is now
git checkout -B dev master
git push
# now let's "repair" master
git checkout master
git reset --hard <oldMasterHash>
# here we'll need --force to push since this is a history rewrite
git push --force
...and you'll be all set, local and remote.
Upvotes: 2