1 Star 0 Fork 13

江二十三 / git-analyze

forked from GiteeStudio / git-analyze 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Git Analyze tool

在用户使用 git 作为版本控制工具时,可能会将一些体积较大的文件提交到历史记录之中,由于 git 是一个分布式的版本控制系统, 并且基于快照的存储特性,这个时候,用户的存储库提交将变得非常大. git-analyze 是一个可以帮助用户检索出从哪一次提交 引入了原始体积超过限制的文件. git-rollback 则可以根据分支上的 commit 和从当前回退的版本数实现回滚,并且保留当前 工作目录的文件不改变,用户可以重新创建提交.

构建

Windows 依赖:

  • Visual Studio 2019 or Later
  • CMake 3.14 or Later

Unix 依赖:

  • GCC 8.3 or Later (Suggest 9.2)
  • CMake 3.14 or Later
git clone https://gitee.com/oscstudio/git-analyze.git

Windows 构建:

mkdir build
cd build
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release ..
cpack

然后打开安装包即可。这里需要注意,Ninja 并不能很好的支持 cmake ExternalProject 特性,因此会构建失败。

Unix 构建:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release .. -DCMAKE_INSTALL_PREFIX=/opt/oscstudio
make
make install

Analyze 工具

git-analyze 命令行参数

OVERVIEW: GIT analyze tools
Usage: git-analyze <options>...] [--] [<pathspec>...] [<refs|branches> ...]
OPTIONS:
  -h [--help]      print usage and exit
  --limitsize      set analyze engine limit blob size
  --warnsize       set analyze engine warn blob size
  --timeout        set analyze engine lifycycle
  --who            show who is commit author
  --all            analyze will scanf all refs

默认情况下, git-analyze 扫描当前目录的仓库的 HEAD 指向的分支,如果要扫描其他目录或者其他分支需要额外的设置参数, 仓库目录可以是工作目录的根目录和裸仓库的目录, 分支名可以使用引用或者本地分支名,二者相对顺序必须与下相同.

git-analyze /path/to/repo master

其中 limitsize warnsize 参数都是整数,单位是 MB 默认值为 100 MB 和 50 MB, timeout 单位是秒,可以不设置, 这几个都可以使用 --limitsize=100 或者 --limitsize 100 这样的格式.

who 这个参数是一个开关,单命令行参数中存在 --who 时, 扫描到大文件时将显示提交 作者 和 提交信息.

all 这个开关如果开启时,将扫描所有的引用.

这些参数没有顺序要求.

例图:

Analyze Example

Rollback 工具

git-rollback 命令行参数

OVERVIEW: GIT rollback tools
Usage: git-rollback <options>...] [--] [<pathspec>...] [<refs|branches> ...]
OPTIONS:
  -h [--help]      print usage and exit
  --git-dir        set rollback repository path
  --backid         set rollback commit id
  --backrev        set rollback current back X rev
  --refname        set rollback current reference name

参数格式与 git-analyze 类似, --force 将强制运行 git gc 并清除悬空对象. 当 未指定 git-dir 时,为当前目录,未指定 refname 时,为 HEAD 指向的分支.

Cheat 工具

git-cheat 可以基于当前分支创建一个只有一个 commit 的分支,此分支的提交信息,树对象等都与当前分支 一致,但没有父提交。很容易看到的一个场景是,用户清理项目后,创建一个提交,然后在此提交的基础上 使用 git-cheat 开源。

命令格式:

git-cheat branch commit-message

Pre-Commit 工具

pre-commit 是 git 的一类钩子,当用户创建提交,也就是 git commit -m 后,如果存储库中有此类钩子, git-commit 就会执行 pre-commit 钩子,用户在创建提交时,很容易将大文件或者二进制文件提交到存储库, 等到推送到代码托管平台被拒绝时撤销更改就非常麻烦了。使用 pre-commit 可以避免此类问题, 用户将 pre-commit 软链到 .git/hooks/pre-commit 就行了,如果要修改配置,可以使用 git config 修改, git config 添加 --global 参数时修改全局设置。

这里 limitsize 即限制文件大小,单位可以是 K M G 不区分大小写。warnsize 是警告提示大文件,大小为 limitszie 的一半就可以了。

而 filters 是一个正则表达式,过滤后缀名的,一般网络上可以找到。filterbroken 是设置当存在过滤文件时是否终止提交。默认为 false。

git config commit.limitsize 100M # limit file size
git config commit.warnsize 50M # report warning file size
git config commit.filters "\.(exe|obj|pdb)$" # filter regex
git config commit.filterbroken true # filter broken when find

Git Complete 工具

此工具创建 整整一年的提交

git-complete dir branch 'commit message' 2018~2100

Update 钩子

Update 钩子是一个实验性的钩子用户实现 git 只读目录功能,相关的原理可以查看 实现 Git 目录权限控制

与 GIT 整合

git 支持使用 git subcommand 的格式运行特定命令,比如 git add 对应的命令就是 git-add , 当用户需要直接运行 git analyze 这种方式运行这些命令, 有几种方法可以做到,第一种是将 git-analyze 加入环境变量,然后可以直接运行

 git analyze . refs/heads/master
 git rollback --backrev 1

同样也可以使用软链接的方式将命令链接到系统目录, 在 POSIX 系统中,或者 Windows Subsystem for Linux 可以使用 ln -s , 在 Windows 中 可以使用 mklink /d .

Copyright

Author: Force Charlie
Copyright © 2020, GITEE.COM, All Rights Reserved.

Copyright (c) 2020 GITEE.COM. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

git Analyze tool [Cross Platform] 展开 收起
C++
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C++
1
https://gitee.com/ipvb/git-analyze.git
git@gitee.com:ipvb/git-analyze.git
ipvb
git-analyze
git-analyze
master

搜索帮助