将命令应用于所有提交 [英] Apply a command to all commits

查看:49
本文介绍了将命令应用于所有提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了收集有关Git存储库的一些统计信息,我正在寻找一种执行以下操作的方法:

In an attempt to gather some statistics about a Git repository, I'm looking for a way to do the following:

  • 对于每个提交,执行一个命令(例如; du -h).
  • 该命令应在提交后从存储库基本目录按其外观"运行.
  • 理想情况下,该命令可以访问提交哈希和时间戳.
  • For each commit, execute a command (ex; du -h).
  • That command should run from the repository base directory "as it looked like" after the commit.
  • The command would ideally have access to the commit hash and time stamp.

将以准Bash表示的一个应用程序将运行

One application, expressed in quasi-Bash, would be to run

echo $HASH $TIME `du -hs --exclude=".git" . | awk '{ print $1; }'` >> ../sizeovertime

通过所有提交了解存储库的增长.

on all commits to get an idea of the growth of the repository.

(以某种方式,感觉应该可以使用git filter-branch --tree-filter,但这对我来说似乎是一个可怕的技巧.)

(Somehow, it feels like it should be possible to use git filter-branch --tree-filter for this but that looks like a terrible hack to me.)

推荐答案

我不明白如何在不检查每个提交的情况下执行此操作,因此在大型存储库上将花费一些时间.

I don't see how you could do this without checking out each commit, so that is going to take a while on a large repository.

这是使用bash进行操作的方法:

Here's how you could go about it with bash:

#! /bin/bash

while read co dt ; do
    git checkout $co > /dev/null 2>&1
    size=$(du -hs --exclude=.git|cut -f1)
    echo $co $size $dt
done < <(git rev-list --pretty=format:"%H %ci" --all --date-order |grep -v "^commit")

警告:这将使您处于分离状态,处于最旧的提交状态,这不是一个好地方.

Warning: this will leave you in detached head state, on the oldest commit, which is not a nice place to be.

这篇关于将命令应用于所有提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆