Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove merge commit from PR?

Tags:

git

github

I have a PR up on github and I accidentally merged master into my PR and pushed it. Now the PR shows way more files changes than the ones just changed by me because the master was merged in. How can I just delete the previous to merge master commits from the PR?

I tried doing git revert <hash> and now the PR commits look like this. However, the total number of Files Changed is still incorrect. It is showing files that I didnt' change.

The PR commits look like this:

My good commit

Merge branch 'master' into this-prbranch

Revert "Merge branch 'master' into this-prbranch"
like image 348
Anthony Avatar asked Nov 02 '25 12:11

Anthony


1 Answers

You can first locate the merge commit with git log, take down its SHA.

Then, revert your tree to the point before it:

git reset --hard abcdef8~

(apparently you should replace abcdef8 with the SHA of the merge commit)

And force-push the reverted tree:

git push -f

Why does git revert not work as expected?

From git-revert(1):

Given one or more existing commits, revert the changes that the related patches introduce, and record some new commits that record them.

like image 190
iBug Avatar answered Nov 04 '25 03:11

iBug