timpone
timpone

Reputation: 19969

Trying to understand how git --graph works and showing branches

I've been using Git for a while, but more casually just merging in topic branches and pull requests. I'm not understanding what git log --oneline --graph is telling me here. The two branches shown are master and my6.

enter image description here

Specifically, I don't understand the 4e4e1fd jt2 on master commit which seems like it's on the wrong branch. Is the star on the left branch showing what branch it's in?

To get here, I:

  1. edited file and commit 'jt on master' on master branch
  2. created and checkout outmy6 branch
  3. made edits and commit as '#1 on my6'
  4. checked out master
  5. made edits and commit as 'jt2 on master'
  6. merged my6 branch onto master; should be a 3 way merge

The graph is obviously correct but it seems like 4e4e1fd jt2 on master is on the wrong branch, appearing on the my6 branch rather than master. What am I not understanding?

Upvotes: 0

Views: 261

Answers (1)

Makoto
Makoto

Reputation: 106410

It's on the right branch. Here's how we know:

  1. checked out master
  2. made edits and commited as 'jt2 on master'

You checked out your master branch, then made the changes on it directly. You then went back to your other branch and made other changes. This is why you don't see the change on my6; there's nothing yet linking their ancestry chain together.

When you merge my6 into master, both commits appear as they should, and there really shouldn't be any three-way merges unless it was the same file.

If you want to audit this, you can check git reflog, which will give you a synopsis of every action you've taken in Git so far, up to about 3 months. You'll be able to see which branch you were on when you commited and merged.

If you want to improve the layout you get from the terminal, then you can use git log --graph --oneline --decorate, which will give you more context into the branches and what is on them.

Upvotes: 1

Related Questions