I recommend to look into git log --help and git rev-list --help .

I just created 2 scripts to list commits from Git repositories. It’s more in the score of an alias actually, so nothing comprehensive here. If you have some one-liners, alias or scripts for commits listing, please share here. The link of this post goes to the git log documentation. I’ll share mine in the comments too rather than in the post.

  • Morphit @feddit.uk
    link
    fedilink
    arrow-up
    2
    ·
    8 days ago

    cat .local/bin/git-lastblame

    #!/usr/bin/env bash
    #Show when <paths> were last committed, with date, author and commit title
    
    paths=("$@")
    if ((${#paths[@]} == 0)); then
        paths=(".")
    fi
    
    while IFS=$'\t' read -r hash file; do
      git log -n1 --pretty=format:"%h:%Cblue%as%Creset %Cgreen%an%Creset %Cblue$file:%Creset%s" --no-patch $hash
    done < <(git last-modified ${paths[@]})
    

    By default it will show all the files in your current directory. I like it to get an idea of of the lifecycle of one area of a project. Files will be listed ordered by most recent commit. Note that it’s not very fast so it’ll probably choke on big repos. Alias as g lb - press few key.

    • thingsiplay@lemmy.mlOP
      link
      fedilink
      arrow-up
      2
      ·
      8 days ago

      This is an interesting one. But there is probably a better way instead running a Git command for every single file.

      • Morphit @feddit.uk
        link
        fedilink
        arrow-up
        1
        ·
        8 days ago

        You’re absolutely right. Here’s a slopcoded rewrite that does run a ton faster and doesn’t use git last-modified (which is labelled experimental but was kind of the original inspiration). I even got it to do relative filenames instead of the full path to the root of the repo which I had been wanting.

        cat .local/bin/git-slopblame

        #!/usr/bin/env bash
        # Show when <paths> were last committed, with date, author and commit title
        
        paths=("$@")
        if ((${#paths[@]} == 0)); then
            paths=(".")
        fi
        
        git log --format='@@@%h%x09%as%x09%an%x09%s' --relative --name-only -- "${paths[@]}" |
        awk '/^@@@/ {
                commit = substr($0, 4)
                next
            } length($0) && !seen[$0]++ {
                print commit "\t" $0
            }' |
        while IFS=$'\t' read -r hash date author subject file; do
            printf '%s:\033[34m%s\033[0m \033[32m%s\033[0m \033[34m%s:\033[0m%s\n' \
                "$hash" "$date" "$author" "$file" "$subject"
        done