Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git revert to old commit in remote

Tags:

git

git-bash

I want to revert code to an older commit in my remote repo's master branch. But the problem is I do not have administrator rights to directly commit/push anything to the master branch. All I can do is create a new branch from master, do my changes there and then merge it with a pull request to master.

I took a new branch from master, reverted the code to where I wanted but when I try to merge it back to master it says no differences found.

I did the below to revert the code in branch and the revert happens exactly how I want

git reset --hard <commit>
git push --force

How can I merge these changes to master? Is there any other way by which I can revert the code in master?

like image 712
derek Avatar asked Oct 29 '25 17:10

derek


1 Answers

You cannot remove commits from master using a separate branch. Branches are meant for adding commits on the tip of master — that is why your git merge does not work.

Since you do not have permission to force-push directly to master, you would have to create revert commits on a separate branch and merge them in.

git revert COMMIT_HASH_1 COMMIT_HASH_2

This will add a new commit that reverses the changes made in the commits you specify. You can then merge this back into master.

Without permission to force-push directly to master, I believe this would be your best bet. Force pushing to master is usually disabled to prevent exactly what you are trying to do — rewrite history.

like image 107
Ali Samji Avatar answered Oct 31 '25 07:10

Ali Samji



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!