How to git blame a directory

前端 未结 3 761
长发绾君心
长发绾君心 2021-02-06 23:35

I would like to know how to use git blame to know who created a single directory.

When I try:

git blame DIRECTORY_NAME

I get:



        
相关标签:
3条回答
  • 2021-02-07 00:14

    To git blame the current directory:

    git ls-files -z | xargs -0n1 git blame
    

    I adapted the above from here: https://gist.github.com/Alpha59/4e9cd6c65f7aa2711b79

    A very very slow one-liner that goes through a git blame and sees how many lines were contributed by each author.

    It seems I needed to press spacebar and Q at least once to fully scroll through the list.

    0 讨论(0)
  • 2021-02-07 00:15

    Try getting a log of just that directory, and use the -p option to see the exact changes that occurred.

    $ git log -p <path to directory>
    

    This still might not tell you exactly who created the directory, since git seems to focus more on file content, but you might get some helpful clues just from seeing the first time any content was added to it.

    0 讨论(0)
  • 2021-02-07 00:17

    I created a small function what loops over all files and makes a directory blame view similar to GitHub.

    Output format is:

     FILENAME      COMMIT-HASH  Commit-DATE  AUTHOR  COMMIT-MESSAGE
    

    looks like this

     myfile1    abceeee 2019-04-23 19:26  Radon8472  Added file example
     readme.md  abd0000 2019-04-24 19:30  Radon8472  Update Readme-File
    
    blamedir() 
    { 
      FILE_W=35; 
      BLAME_FORMAT="%C(auto) %h %ad %C(dim white)%an %C(auto)%s"; 
    
      for f in $1*; 
      do 
        git log -n 1 --pretty=format:"$(printf "%-*s" $FILE_W "$f") $BLAME_FORMAT" -- $f; 
      done; 
    }; 
    

    usage-eamples:

    • blamedir similar like blamedir ./
    • blamedir DIRECTORY_NAME/

    Feel free to change the display format by changing the Variable BLAME_FORMAT in the function.

    I think it should be possible to set this function as git-alias too.

    0 讨论(0)
提交回复
热议问题