Search code examples
gitintellij-ideacommitphpstorm

Git commit list


I guess I'm just missing some important point in git. I'm using PhpStorm IDE for development process and GIT as a VCS. Everytime I pull changes from one of the developers branches I get a list of commits of other developers, it's perfectly normal. But when I'm pushing the changes I push not only my commits a made locally but also commits that were retrieved with pull.

But why is this happening? Why other developers commits is in my push? I though as long as GIT stores those developers commits on remote branch they are already pushed. Am I missing something?

GIT commands (according to IDE history):

git pull --no-stat -v --progress origin trunk

git push origin trunk:trunk

GIT version: 1.7.4.4, OS: Mac OS X 10.7


Solution

  • As Vonc said, when you run git pull origin trunk, git first runs a fetch (git fetch origin trunk), which takes the branch 'trunk' from the remote 'origin', and stores it in FETCH_HEAD.

    Note that this is potentially unexpected behaviour, and a very good reason not to use the "4-argument" forms of git-pull and git-fetch.

    Anyway, after running the fetch, git runs git merge FETCH_HEAD. This takes the newly-fetched remote branch, and merges it into the local branch. You've just taken you local branch, and the 'trunk' branch from 'origin', and merged them together.

    If you're having trouble visualising this, try running gitk or git log --graph --oneline --decorate to view the history graphically. You should be able to see the two lines of history (yours and the remote one) being merged together. git log, without --graph or --first-parent, etc, will display all commits reachable from the current branch, but won't distinguish between which branch they're actually on.

    Unsurprisingly, then, when you run git push, git takes this merged history, and pushes it.

    You probably meant to run git fetch or git fetch origin rather than git pull origin trunk. This will fetch the updated branches from 'origin', and store them in your remote-tracking branches (such as 'origin/trunk'). You can then inspect this with e.g. git log origin/trunk. If you then want to merge 'origin/trunk' into your local branch, use git merge origin/trunk.