Extra Merge Commits

Extra merge commits are made when you commit changes locally, then run git-pull to update your local repository with the changes that have been pushed to the central repository.

The exact error message you get if you try to push a branch with extra merge commits to GNOME repositories is:

The commit:

[commit info here]

Looks like it was produced by typing 'git pull' without the --rebase
option when you had local changes. Running 'git  pull --rebase' now
will fix the problem. Then please try, 'git push' again. Please see:


The problem occurs because the normal modus operandi of git-pull is to git-fetch first, then do a git-merge. The git-fetch part simply fetches all new objects from the remote repository, without changing your local branches at all. The git-merge part, tries to merge your changes with those from the remote branch. That is, after the fetch, it your git repository may partially look like this:

    ---- time --->

 o--o--o--o--o--o <-- origin/master
            o--o <-- master

where origin/master is what's in the central repository's master branch, and master is your local working branch (similarly for branches other than master or remote repositories other than origin).

Now what git-merge does it to merge the origin/master and master branches and save that action as a merge commit:

 o--o--o--o--o--o--o <-- master
          ^       /
           \     /
               ^ old master

The new commit, at the tip of the master branch is the new merge commit. While this is perfectly legitimate, this clutters the project history unnecessarily in case of small changes. This is what this error message is about.

What you can do, is to rebase you changes on top of the new origin/master, and the repository will simply look like:

 o--o--o--o--o--o--o--o <-- master
               ^ dead, old, master

To achieve this you simply need to run:

git rebase origin/master

which means: replay my changes on top of the origin/master branch.

The git-pull command has an option to do this by default, and that is achieved by using:

git pull --rebase origin/master

instead. Or you can configure git to perform that by default. Just do:

git config --global branch.master.rebase true

If you drop the --global option, this will be saved for your current git repository only, whereas with the --global option it will change the default behavior of git-pull for all git repositories you deal with.

For more information see git-merge manual. For much more information about branches and merging see this article.

Git/Help/ExtraMergeCommits (last edited 2009-04-24 04:10:01 by BehdadEsfahbod)