2

When I used gitk to check my branches, I found the following:

Git connected branches

I created pretty_url, switched to it, worked on stuff, committed, then switched to master branch (which was clean), then ran git merge pretty_url, and checked with gitk, and found this.

I'm sure this is not proper and probably the master wasn't clean. How can I fix this?

Victor
  • 13,010
  • 18
  • 83
  • 146
  • 1
    @FabioA.Correa, the master branch is not one line... – Victor Aug 21 '13 at 16:16
  • @FabioA.Correa Proper one should have one pink line, that's all. But right now it's branched out to another red line. – Victor Aug 21 '13 at 16:20
  • I don't think there is a way to control how it displays it, unfortunately. http://stackoverflow.com/questions/4511416/gitk-weird-history-tree – wisbucky Jan 09 '14 at 10:38

2 Answers2

6

That's exactly what you should expect from a merge. If you wanted to rebase and fast-forward, you could have done that instead and had a straight line.

Example:

Before the merge, you had this situation:

before pic

That is, the history of master and branch diverged. They share h as a common ancenstor. When merging (via git merge branch while on `master), you end up with a commit with two parents to unify that history:

merge pic

If that's not what you wanted, you can undo that and get what you wanted by doing something like:

git reset --hard HEAD@{1}  # or whatever commit matches 'j' to undo the merge
git checkout branch
git rebase master          # incorporate 'i' and 'j' commits into 'branch'
git checkout master
git merge branch           # this merge will be a fast-forward now

Which will give you the rebased linear history you seem to be looking for:

fastforward pic

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
  • I don't think that's what the OP is looking for. I believe what he wants is for all the Master branch commits ("a" to "j", "merge branch") to be in one line. And all the Other branch commits ("k", "l") to be in another line. That makes a lot more sense logically. Here is a related question: http://stackoverflow.com/questions/4511416/gitk-weird-history-tree – wisbucky Jan 09 '14 at 10:33
4

The red line does not indicate an unclean branch; it just means that the previous commit in master is older than pretty_url's head. No need to worry here. Moreover, git merge does not work on unclean trees.

Fabio A. Correa
  • 1,968
  • 1
  • 17
  • 26