Anthony
Anthony

Reputation: 35988

How to remove merge commit from PR?

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"

Upvotes: 4

Views: 6536

Answers (2)

iBug
iBug

Reputation: 37287

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.

Upvotes: 5

user3675515
user3675515

Reputation: 165

  • run git log to see all commits
  • copy a commit hash before your merge
  • run git rebase -i <commit hash> to rebase
  • and push changes git push -f

Upvotes: 0

Related Questions