4

I use git log, but I find it can only list logs under current branches, but I want to list all the loges for all the branches and sort by modified date, is that possible ? How to do that ?Thanks in advance !

MemoryLeak
  • 7,322
  • 23
  • 90
  • 133

2 Answers2

4

You can check this question to see if this begin to address your log level:

git log --graph --abbrev-commit --pretty=decorate --branches

it should list all branches including remotes ones (if fetched)

--branches[=pattern]

Pretend as if all the refs in refs/heads are listed on the command line as <commit>.
If pattern is given, limit branches to ones matching given shell glob.
If pattern lacks ?, , or [, / at the end is implied.


You can try this commandline-fu, with git branch or git branch -a:
(git branch -a is certainly what you need of you want to see the same branches than gitk)

for k in `git branch -a|perl -pe s/^..//`;do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset%cn: %s" $k|head -n 1`\\t$k;done|sort -r

or:

for k in `git branch -a|sed s/^..//`;do echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset%cn: %s" "$k"`\\t"$k";done|sort

(you can complete the format to show any data -- author, commit message, ... -- you need)

Show git branches by date - useful for showing active branches Print out list of all branches with last commit date to the branch, including relative time since commit and color coding.


Note: As Jakub Narębski aptly comments:

Don't use git branch output for scripting!!! Use git for-each-ref or git show-ref plumbing (low-level commands meant for scripting)

git branch is a porcelain command precisely because it meant for user, and not for scripting.

As Eric Raymond puts it, It fits the well-established git design philosophy of separating content manipulation (plumbing) from presentation (porcelain).

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 4
    Don't use `git branch` output for scripting!!! Use `git for-each-ref` or `git show-ref` plumbing (low-level commands meant for scripting). – Jakub Narębski Jun 05 '10 at 11:38
  • 1
    Plumbing commands are difficult as Indonesian hell, learning them on the level where you can write helpers that answer simple questions like "is the tree clean" takes a year, and **still** the helper ends up 200+ loc. The idea of "porcelain is for people, plumbing is for scripts" overlooks the fact that it's people who write scripts. – Szczepan Hołyszewski May 09 '16 at 16:09
1

git log --all

Matt Curtis
  • 23,168
  • 8
  • 60
  • 63
  • tested, but only display the log of master branch – MemoryLeak Jun 05 '10 at 03:37
  • 1
    It certainly can't list the logs of a different branch on a remote machine, without first merging them into the current branch. What other references would you want it list? A subset could be shown by the `git branch -a` command. – Arafangion Jun 05 '10 at 04:01
  • but in gitk gui, I can see all the logs include all the branches!How can I get that with command line ? – MemoryLeak Jun 05 '10 at 04:09
  • 1
    That behavior should be provided by the --all argument, as mentioned. See the git documentation for that command. (Is it possible that the commits you expect to see are lost in the noise? Also keep in mind that gitk also looks at the index). – Arafangion Jun 05 '10 at 04:16
  • are you kidding me ? I tried your command again,but still not work. miss the logs in the branch I just modified. – MemoryLeak Jun 05 '10 at 04:46
  • What kind of branches are we talking about? The branches you are interested in are evidently not in .git/refs. In that case, see VonC's answer. Keep in mind that a "branch" is really a named head. Any commit could be a branch, depending on how you choose to define it. – Arafangion Jun 05 '10 at 04:57
  • actually i don't name the branch, i just use checkout to revert to previous version as a branch – MemoryLeak Jun 05 '10 at 07:31
  • If you're just checking out a commit, there is no branch. Git will warn you of this when you check out. – Matt Curtis Jun 05 '10 at 10:19
  • but in the git gui, it draw a branch from master, so I think it's a branch, is there any mean I can update the master to previous version? just like svn update?(but not create a new branch) – MemoryLeak Jun 05 '10 at 11:02
  • 1
    @MemoryLeak: To pick up a detached HEAD you need to include HEAD with `--all`: `git log --all HEAD` – Chris Johnsen Jun 05 '10 at 20:52
  • fatal: ambiguous argument 'HEAD': both revision and filename Use '--' to separate filenames from revisions ---- I got this error message – MemoryLeak Jun 05 '10 at 22:42