Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pull request on github - showing commits rebased from master

Tags:

git

github

I'm working with a team and we're doing feature branches and pull requests.

I created a branch, worked on it a bit while also doing little work on master.

Then, I rebased the branch against master. Now I want to do a pull request.

However, in GitHub, the pull request shows all the commits that happened between when I first made the branch and now - the commits I did on this feature branch, and the commits that are on master that happened in between.

This is noisy clutter - am I doing something wrong? I'd like the pull request to just show the commits that I've made, since the other commits are already on both master and on my branch, no difference.

The only suggestion I see is making another branch based on the latest upstream master and cherry picking commits from my branch onto it.

like image 725
Hsiu Dai Avatar asked Aug 19 '13 21:08

Hsiu Dai


People also ask

Why is GitHub showing all my previous commits in every pull request?

This happens with GitHub when you squash commits merged in from the target branch.

What does commits behind Master mean?

The 4 commits behind master just means that your branch is out of sync with the master, and you should do a merge from master to your branch in order to get the latest changes from master into your branch.


3 Answers

I used to have the same problem:

If we have foo branch, branched from master, which is already pushed into origin, and on both branches changes were made, then after merging/rebasing I was getting changes from master in Pull Request's diff.

I solved it by executing git fetch first, updating my local master branch, changing local branch to foo and then executing commands:

git rebase master

git push -f origin foo:foo

This is forcing remote branch and then PR's diff contains only proper changes, exactly as the branch would be created based on recent master.

like image 116
Tomasz Racia Avatar answered Oct 11 '22 00:10

Tomasz Racia


You must have done something wrong. As a result of the rebase, you should have only the unique revisions following the last commit in master, and your branch should be ready for a fast-forward.

I did a quick test now, and of course, the pull request shows only the unique revisions as expected. There should be no noisy clutter, and no need to cherry pick. It seems something is wrong with your branches.

Try to rebase again. If you rebased correctly earlier, this should be a NO-OP now. Checkout your branch, and try to rebase again on top of master, like this:

git checkout yourbranch
git rebase master

This should print Current branch will-have-rebased is up to date., and after you push the branch to GitHub, you should be able to create a pull request where only the unique commits show up. I don't see why not.

Important: keep in mind that if you had pushed your branch before rebasing, then Git will refuse to push again after rebasing. This is because in general you should not rewrite the history of public branches, and all guides on rebasing explain this point. If you want to push the branch anyway, rewriting its history on github, add the --force flag.

like image 43
janos Avatar answered Oct 11 '22 01:10

janos


For me, closing the PR and opening a new one with the same branch did the trick.

like image 1
Mateus Ferreira Avatar answered Oct 10 '22 23:10

Mateus Ferreira