views:

28

answers:

2

Hi ,

I am working in ROR in a Ubuntu machine. I had done some changes in my files and commited it with a msg.

Now when i checked with the git log thing..

I am getting a new msg rite above my commited message as Merge Branch 'myname' .. Why is it so coming like this ?

Please give suggestions..

EDIT :

Date: Mon Oct 11 11:42:29 2010 +0530

Merge branch 'aruna'
A: 

This is a git question and is not related to Rails.

So - it is quite normal in git and it will happen in situation like this

               - aruna: X -> Y 
              /
master: A -> B -> C -> D .....

when you merge aruna with master (either by doing merge aruna on the master branch or just by pulling [pull is "two in one" command - it makes fetch & merge]) you will get new "merge" node that is the merge of both branches (nodes C, D & X, Y)

As you are asking I bet that you don't like it. So the possible solution is to rebase the aruna branch instead of merge. For example:

# normally commit everything in your aruna branch
git checkout aruna
git add ... 
git commit -m "..." ...

git checkout master
git pull # it will just fetch as there is nothing to be merged
git checkout aruna
git rebase master # and solve possible conflicts
git checkout master
git merge aruna # it will *not* make the "merge node"
git push

EDIT: As others mentioned - the rebasing is really no option if you already pushed the branch or you have other people who pulled your branch.

But still - rebasing is an option if you are merging your local private branch. Which is a quite common scenario. And as your branch is named "aruna" (your name) I thought that's the case. But as I think about it again there is no reason to think so :-)

While rebasing (local feature branch), you will lost some part of history that says that you did your commits in parallel. But the trade-off is that you will have simpler narrow tree.

pawien
actually rebasing in this situation is a bad idea since (1) he might have pushed his changes (2) your history should reflect what actually happened not what you wish happened ("all this work was done after all the work on the mainline")
Idan K
+1  A: 

You shouldn't worry about git "merge commits". The merge commit just contains the differences between your local version of the branch and the remote version of the branch. (hence why they appear when you pull and there were any changes).

Rebasing, exactly as suggested in pawien's answer is a good way to avoid those, but only if you know what you are doing. Rebasing should only ever be used in a local feature branch (a branch that you never push), because it re-writes all the commits that have been commited to the feature branch. rebasing a branch that has other peoples commits in it can accidentally delete commit history if you don't know what you're doing.

Jeremy
agree - I made a (wild) guess in my answer. The branch mentioned in the question is named "aruna" which is same as user name. So I thought that it is a local branch. In that case the rebasing is in my opinion better way because it's history nobody is interested in. But totally agree with you - it should be used *only* in that case.
pawien
I've started trying to use rebase myself in my workflow (along the lines of http://reinh.com/blog/2008/08/27/hack-and-and-ship.html) now that I'm working with a team bigger than one or two people because the end result produced is definitely much nicer (especially the ordering of commits in a feature branch next to each other), however despite having worked with git for over a year, I've still messed things up a couple of times, hence why I'm shying away from suggesting someone new to git use rebase.
Jeremy