Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does git log work across branches?

I'm using a github repository and it has a master branch and a demo branch. All was good and both the master version and the demo version of the code are in use (master on a staging site, and the demo on a demo site). A live site runs on a tagged commit.

While making changes, I messed something up which did not reveal itself for a while so I needed to start looking through old commits to see how I introduced the problem.

On Github I saw commits for the demo branch as follows:

Changed logos to xxx ones
8c4a3eab22 Browse code 
pwhipp authored 3 days ago
Feb 04, 2014
Paul Whipp
Changed archetype age_default to default to zero (and set all null va… …
6e4c9e8864 Browse code 
pwhipp authored a month ago
Feb 03, 2014
Paul Whipp
Added demo.xxx allowed domain for RED
2f72e3b05a Browse code 
pwhipp authored a month ago

So on a local repo, pulled up to date, I do "git checkout 8c4a3eab22". Then when I invoke git log locally, I see:

(red)~/wk/red $ git status
# HEAD detached at 8c4a3ea
(red)~/wk/red $ git log
commit 8c4a3eab22dc2ce9708c9aae00751e558ae81dd3
Author: pwhipp <[email protected]>
Date:   Thu Feb 27 10:55:21 2014 +1000

    Changed logos to xxx ones

commit 2f72e3b05a005738d77ed12be475634aadf76b49
Author: pwhipp <[email protected]>
Date:   Mon Feb 3 10:58:08 2014 +1000

    Added demo.xxx allowed domain for RED

Why is 6e4c9e8864 not shown by git log? It exists (I can check it out) but the differences between it and 8c4a3eab22 seem far greater than those indicated when I browse 6e4c9e8864 on github so I'm thinking there may be other commits I'm not seeing.

Do I need to RTFM somewhere to understand how the commits are being reported in the log call across the different branches?

like image 252
Paul Whipp Avatar asked Aug 28 '26 05:08

Paul Whipp


1 Answers

It's difficult to say how the problem came into being without more information. However, a few points may help you diagnose it.

  1. A commit can "exist" (be able to be checked out) without being a part of the branch's history. For example, if I have two diverging branches b and c which both have a common point a. If I'm in branch b I can still checkout commits that are unique to branch c without having to first check out that branch. You can use git reflog to get a full story of what has happened to the repository in the past. A branch is just a label for one of these points in git's history.
  2. It's better to avoid git pull since it fetches and merges from the remote. In this case you may have merged into the wrong branch (e.g. merged remote master into local demo) which would could cause different results than you expected.
  3. The commit may have been pushed to the remote and then later removed/squashed locally with a git reset or git rebase. In this fashion, it would show on github but not in your local repository.
like image 101
Conner Avatar answered Aug 29 '26 20:08

Conner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!