git 调查谁提交的大文件

一、背景

一些新手会往git仓库提交一下大文件,撑大代码库,如果这种事情已经发生了,怎么定位到具体是哪个开发干的?

二、方法

通过以下3个步骤,基本上能够定位到是谁做的提交了

2.1 查找当前代码库有哪些大文件

新增脚本gitlistobjectbysize.sh(这个是我在网上找的)

  #!/bin/bash -e

function main {
    local tempFile=$(mktemp)
    # work over each commit and append all files in tree to $tempFile
    local IFS=$'\n'
    local commitSHA1
    for commitSHA1 in $(git rev-list --all); do
            git ls-tree -r --long "$commitSHA1" >>"$tempFile"
    done
    # sort files by SHA1, de-dupe list and finally re-sort by filesize
    sort --key 3 "$tempFile" | \
            uniq | \
            sort --key 4 --numeric-sort --reverse
    # remove temp file
    rm "$tempFile"
  }
main

在代码仓库目录执行脚本

sh gitlistobjectbysize.sh > obj-size

通过这个命令可以找到可疑文件的路径(path)+哈希(hash)

2.2 大文件属于哪个commit

git log --all --pretty=format:%H -- build/releasebin_mptool.zip | xargs -I% sh -c "git ls-tree % -- <path> | grep -q <hash> && echo %"

2.3 comit属于哪个分支

git branch -a --contains  <commit>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容