Anurag Sharma
Anurag Sharma

Reputation: 2605

Remove a commit from a master branch through a pull request

I have to remove a commit from the master branch which is locked for direct commits and only allows commits through pull requests.

I followed following steps:

git checkout -b commitreversal
git reset --hard HEAD~1
git push origin commitreversal --force

When I try to raise pull request with commitreversal branch it says

"There isn’t anything to compare. Master is up to date with all commits from commitreversal."

What should I do?

Upvotes: 1

Views: 54

Answers (1)

Gimly
Gimly

Reputation: 6175

You can't rewrite Git's history through a pull request. You'd have to do a git push --force, and since your master branch is locked, it's likely that you don't have the administrative privilege to do that.

If you really want to rewrite history, then you'll have to check with someone who has administrative privilege for that repository and ask him to do the change and do a git push --force. That will mean that everyone who has a clone of that repository will basically have to re-clone it (or reset hard) to get back to a working version.

Or, as @jonrsharpe suggested, you should do a revert instead of a hard reset.

git revert commit-id

where the commit-id is the hash id of the commit you're trying to remove.

which will have the effect of removing all the changes that were made during that commit, without changing git's history itself. You will be able to create a pull request on that.

Upvotes: 2

Related Questions