version control - Why does git merge a branch into itself? -


i awoke morning , looked @ commit history of 1 of dev team's private repositories on bitbucket. saw this:

anonymous committed fcde879 merge

merge branch 'develop' of https://bitbucket.org/abc/xyz develop

this is, uh, unusual. guess pushed new machine didn't have git configured properly. still, not sure why doing this. on bitbucket, shows 2 separate hashes commit parents, not have "view raw commit" option of other commits.

i checked out branch, pulled, , looked @ log manually.

sidious@ds-1:/path/to/repo$ git log -1 --format=raw tree 2931d14f48e61eaf0bbe0660af5b5dd76c07f063 parent 6bb38dee681df7620ffa42b6790641a7873166f2 parent f59c82e19e3e79310a53e273bab78139c49ff063 author root <root@somemachine> 1437069530 +0000 committer root <root@somemachine> 1437069530 +0000  merge branch 'develop' of https://bitbucket.org/abc/xyz develop 

as far can tell, 6bb parent on develop branch , f59 parent appears different branch. kinda hard tell going on.

i searched not find answer, , need grind, posit query here: why git merging branch itself? or, rather, why nomenclature being used commit message?

this scenario not unusual.

the key here branches being merged different: it's remote repository's develop branch being merged developer's local (working) develop branch.

in developer's local repository there 2 distinct branches:

  • develop = branch works on. commits go here.
  • origin/develop = snapshot current repository holds state of develop branch on remote server. gets updated remote changes when fetch or pull, , local changes after successful push.

now, when git pull, 2 things happen. because git pull alias other 2 git operations: fetch , merge:

  • fetch - brings new commits (if any) remote repository local origin/develop branch.
  • merge - takes new commits , applies them local working develop branch. can happen in 1 of 2 ways:
    • if local working branch not contain divergent history (new commits remote not know about), advances develop branch pointer ahead, points latest commit in origin/develop. known fast-forward merge.
    • if developer has new commits of own not present in remote repo, and, therefore not in origin/develop branch, regular merge done, meaning there's new commit, containing changes both branches. default, git assigns messages these such commits: merge branch 'develop' of https://bitbucket.org/abc/xyz develop.

so, scenario pretty common one.

now, if happens , don't see complex commit history graphs containing commits 1 we're talking about, try looking using rebase instead of merge.

you can 2 ways (when getting changes remote server):

  • git fetch; git rebase
  • git pull --rebase

Comments