Git - get all commits and blobs they created

后端 未结 6 1266
天涯浪人
天涯浪人 2020-12-05 03:07

Is there a git command that can output for every commit:

  1. id
  2. subject
  3. blobs it created with they path and size (like git ls-tree -l -r &l
6条回答
  •  遥遥无期
    2020-12-05 03:42

    Relying on git rev-list is not always enough because it

    List[s] commits that are reachable by following the parent links from the given commit(s) [..]

    (git help rev-list)

    Thus it does not list commits that are on another branch and it does not list commits that are not reachable by any branch (perhaps they were created because of some rebase and/or detached-head actions).

    Similarly, git log just follows the parent links from the current checked out commit. Again you don't see commits referenced by other branches or which are in a dangling state.

    You can really get all commits with a command like this:

    for i in `(find .git/objects  -type f |
                 sed 's@^.*objects/\(..\)/\(.\+\)$@\1\2@' ;
               git verify-pack -v .git/objects/pack/*.idx  |
                 grep commit |
                 cut -f1 -d' '; ) | sort -u`
      do
      git log -1 --pretty=format:'%H %P %ai %s%n'  $i
    done
    

    To keep it simple, the loop body prints for each commit one line containing its hash, the parent hash(es), date and subject. Note, to iterate over all commits you need to consider packed and not-yet packed objects.

    You can print the referenced blobs (and only created ones) by calling git diff-tree $i (and greping for capitial A in the fifth column) from the loop body.

提交回复
热议问题