Home > Mobile >  This git log output shows two branches as if they weren't branches? Please explain
This git log output shows two branches as if they weren't branches? Please explain

Time:12-07

feature/XY is the name of a feature branch and is currently checked out. feature/XY-refactor is the name of another branch, that branched off of feature/XY.

When I run git log --oneline, I get the output below. What does it mean that these two are right one after the other at the very top of the log output? I am using git bash on Windows.

user@host ~/Documents/repo (feature/XY)
$ git log --oneline
9feb11a (HEAD -> feature/XY, origin/feature/XY) Axis labels
d250b90 (feature/XY-refactor) Refactored
87d49c1 Fix typoe
6a8a7c7 Fix print statement
945ffca Fix code layout
3e747c9 Added spaces after comma
b143713 Changed fontsize
a669cd4 Commented out a print statement
// .. more commits

CodePudding user response:

It can mean a number of things, because the git log command you ran simply shows a list of commits in chronological order but not their relationships.

To see the relationships between commits, use the --graph switch, which works especially well with --oneline:

git log --oneline --graph

For example, if feature/XY-refactor branched off at commit 3e747c9, you might see the following:

$ git log --oneline

* 9feb11a (HEAD -> feature/XY, origin/feature/XY) Axis labels
| * d250b90 (feature/XY-refactor) Refactored
| * 87d49c1 Fix typoe
| * 6a8a7c7 Fix print statement
| * 945ffca Fix code layout
|/
* 3e747c9 Added spaces after comma
* b143713 Changed fontsize
* a669cd4 Commented out a print statement
// .. more commits

I say "might", because you can't make assumptions based on chronological order alone. The true graph could this instead:

$ git log --oneline

* 9feb11a (HEAD -> feature/XY, origin/feature/XY) Axis labels
* 87d49c1 Fix typoe
* 6a8a7c7 Fix print statement
* 945ffca Fix code layout
| * d250b90 (feature/XY-refactor) Refactored
|/
* 3e747c9 Added spaces after comma
* b143713 Changed fontsize
* a669cd4 Commented out a print statement
// .. more commits

When you use --graph, it may reorder the commits to make a cleaner graph.

There is one flaw with git log --graph: It doesn't make it obvious when you have two or more separate commit histories that don't share a common root commit. But that is unlikely to be your case based on what you said.

Anyway, you can always see the history for any particular ref or "commitish". E.g. try these commands:

git log --online --graph feature/XY
git log --online --graph feature/XY-refactor
git log --online --graph HEAD
git log --online --graph 6a8a7c7
git log --online --graph HEAD <some other branch name>

The last one will give the graph for all commits leading up to HEAD and <some other branch name>, showing any connections between them.

As a bonus, here's an even more detailed git log command, showing dates, times and author:

git log --graph --pretty=format:'%C(yellow)%h%Creset %Cgreen(           
  • Related