Reb.Cabin
Reb.Cabin

Reputation: 5567

git log when HEAD is behind tip?

Let's say that HEAD is at the final commit in master, and the log looks like this

$ git log --oneline
bcaee1c 15 July update
02ff17a add feature x
0910b6f end of weekly update
c2b7189 add 03 july update
737be94 add feature y

Now I want to go look at the past:

$ git checkout 0910b6f

now the log shows no hint of the more recent state -- the relative future from HEAD

$ git log --oneline

0910b6f end of weekly update
c2b7189 add 03 july update
737be94 add feature y

Ok, no problem, I just "remember" or "write down" that the furthest-ahead commit is bcaee1c and I can get back with a git checkout bcaee1c, but BAMMO, here comes a phone call, a bunch of emergency meetings, a forced reboot, a weekend, and I "forget" and / or lose the sticky note. I come back (much) later with all that mental context blown and start creating away, only to discover later that I've messed up and have a forensics job with reset and revert and rewind.

Can I get git log to show the future of HEAD? Is there a better git-fu for this scenario?

Upvotes: 0

Views: 2008

Answers (3)

Chris Maes
Chris Maes

Reputation: 37772

Two things to help you:

1 to get back at the tip of your branch (master in your case):

git checkout master

2 for git log to show all commits, and not only starting from head: use --all

git log --oneline --all

NOTE in your case, git checkout master and git checkout bcaee1c might seem to be the same, but it isn't exactly; you must checkout your branch; otherwise you will remain in detached head state.

edit 2 A one-line command that I use a lot to have an overview of the whole tree:

git log --all --online --decorate --graph

Upvotes: 3

Alister Bulman
Alister Bulman

Reputation: 35169

There are some Git Aliases I like to use to be able to see the full layout of tags, and branches are, as well as other useful tips.

in .gitconfig: (in the local, user, or system equivalent files)

# line-breaks for readability, join them to make it work
[alias]
lg = "log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset 
              %s %Cgreen(%Cred%cn%Cgreen:%cr)%Creset' 
              --abbrev-commit --date=relative"
head = !"git log -n1"
l = log --pretty=oneline -n 20 --graph --abbrev-commit

# Show verbose output about tags, branches or remotes
branches = branch -a
remotes = remote -v
tags = tag -l

Other 'dotfiles' are available (on Github, or various Git websites), and I'd encourage you to collect your own!

Here's an example of the git lg alias output

* 37478ff - (HEAD -> master) latest posts (Alister Bulman:6 weeks ago)
* fbde015 - (origin/master) new base URL alias (Alister Bulman:9 weeks ago)
* 5109d77 - new posts and some edits (Alister Bulman:9 weeks ago)
*   1f45eea - Merge branch 'example-blog' (Alister Bulman:1 year, 2 months ago)
|\
| * f361dd6 - new style, and big rebuild (Alister Bulman:1 year, 2 months ago)
* | a60819d - tmp layout files I am trying (Alister Bulman:1 year, 2 months ago)
* | 2b231e0 - new content (Alister Bulman:1 year, 2 months ago)
|/
* 7852089 - (feature/hugo) new posts (Alister Bulman:1 year, 3 months ago)
* ccdc2a0 - fix category tags (Alister Bulman:1 year, 3 months ago)

Very readable. If ytou are working firther back in the tree - then (HEAD) will show further down, and you'll still see the most recent checkin at the top.

Upvotes: 1

Bzil
Bzil

Reputation: 156

To show all your commit, branch, tag you can add this line in the file ~/.gitconfig

tree = log --graph --decorate --pretty=oneline --abbrev-commit --all

You can run it using : git tree

Upvotes: 5

Related Questions