Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github pull request shows too many changes/commits

Tags:

We have two branches: develop and master.

For some reason when I create a PR of develop --> master. It shows a whole list of previous commits and changes even if I've made only a single line change in develop.

Also, it will say "Can't automatically merge" when from the command line I'm able to merge develop into master without a problem.

Any idea what might be going on? Previously it was working fine for us.

EDIT: Here's what it looks like when we try to merge develop to master. Only the most recent commit is new. The others were merged previously: enter image description here And the output of git log --oneline --decorate --all --graph enter image description here

like image 936
Evan Hobbs Avatar asked Aug 19 '16 22:08

Evan Hobbs


People also ask

How many commits in a pull request?

Have one commit per logical change and one major feature per pull request. When you submit a pull request, all the commits associated with that pull request should be related to the same major feature.

How do you exclude changes from a pull request?

To exclude certain files from appearing in pull requests: In the repository containing the pull request, click Repository settings > Excluded files in the Pull Requests section. In the Patterns field, enter patterns to exclude from pull request diff views. Click Save.

Is there such a thing as too many commits?

This error occurs when a push directly to a branch bypassing review contains more commits than the server is able to validate in a single batch.


2 Answers

Your git log shows that there is a lot of commits in the develop branch that don't exist in the master branch. The pull request correctly shows a list of these commits, that can be merged into the master branch.

To list all commits from the develop branch that are not part of the master branch you can use the command git log master..develop. This should match the list you see in the pull request.

From your git log it looks like develop has been merged into master previously. But since these merge commits are no longer in the master branch, is it possible that someone have done a reset of the master branch to an eariler state? Possibly to roll back changes if you have a deployment to an environment synced to the master branch?

Solution

To get master in sync with develop again:

  1. Checkout develop and pull to make sure the branch is up to date
  2. Do the same thing with master
  3. Merge develop into master
  4. Resolve the conflicts
  5. Push the master branch

Now master will be in sync with develop again and the list of commits in develop that master is lacking should be empty. List these commits with git log master..develop. Your next pull request will only contain the commits you do after this merge.

Further investigation

If you want to investigate further how you ended up in this state you can use reflog to see what changes that have been made to the master branch. Fore example if one of the more recent commits in develop previously has been part of the master branch.

git reflog master 

If you want to do this you can do it before you merge the branches so you can see how the history looked before the fix.

like image 62
Niemi Avatar answered Sep 28 '22 03:09

Niemi


I am not sure if I got the op correctly. As I understood you have a single commit in the developmentbranch so here is my try. I am considering the problem that your development branch is not in sync with master

  1. revert back the development branch commit while keeping the local changes git reset --soft HEAD^ # Assuming the last commit is yours

    At this point your local changes will stay in your machine as-is

    Now push this to git .. you may try force push at this point. You can take help from here Rolling back a remote Git repository

  2. Stash the local changes so that you can get these changes in future: git stash

    At this point your development branch is clean and has no local changes

  3. Now switch to master branch and update it with remote. git checkout master & git pull origin master

  4. Switch to development branch and update it with remote. git checkout development & git pull origin development

  5. merge the master to it. git merge master

    At this point your development branch is in sync with master but locally

  6. Push the development branch to remote server: git push origin developent

    Now you can go to the github and raise PR and see if still shows difference. It should not show any such difference if above steps works with no problem.

  7. Now take back your local changes that you stashed in step #2. git stash pop

  8. Now commit it and push to the development branch and see the PR.

If Everything works fine then it should show the correct diff. git clean also might be helpful after step #2.

like image 30
MaNKuR Avatar answered Sep 28 '22 04:09

MaNKuR