6 个版本 (3 个重大更新)
0.5.0 | 2021 年 1 月 11 日 |
---|---|
0.4.1 | 2018 年 7 月 22 日 |
0.3.2 | 2018 年 5 月 14 日 |
0.2.0 | 2018 年 5 月 12 日 |
在 开发工具 中排名第 818
23KB
274 行
git-find
用于在本地 Git 仓库中查找和广播命令的工具(命令行工具 & 库)。
原因
因为我需要一个工具来列出和重组我的本地 Git 仓库。
命令行工具使用方法
$> git find -h
git-find 0.5.0
davidB
A tool (cli & lib) to find local git repositories.
USAGE:
git-find [FLAGS] [OPTIONS] [DIR]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
-v, --verbose Verbose mode (-v, -vv, -vvv, etc.) print on stderr
OPTIONS:
-t, --tmpl <format> format of the output print on stdout [default: {{with .working_paths}}{{if
.conflicted}}C{{else}} {{end}}{{if .modified}}M{{else}}{{if .added}}M{{else}}{{if
.deleted}}M{{else}}{{if .renamed}}M{{else}} {{end}}{{end}}{{end}}{{end}}{{if
.untracked}}U{{else}} {{end}}{{end}} {{ .path.file_name }} {{ .path.full }} {{with
.remotes.origin}} {{ .name }} {{.url_full}} {{end}}]
ARGS:
<DIR> root directory of the search [default: .]
-
默认模板的示例输出(M:未提交的修改,U:未跟踪)
$> git-find . sbt-scalabuff /home/dwayne/src/github.com/sbt/sbt-scalabuff origin https://github.com/sbt/sbt-scalabuff.git MU ML /home/dwayne/src/github.com/samynk/ML origin https://github.com/samynk/ML.git BlenderSourceTools /home/dwayne/src/github.com/Artfunkel/BlenderSourceTools origin [email protected]:Artfunkel/BlenderSourceTools.git three.js /home/dwayne/src/github.com/mrdoob/three.js origin [email protected]:mrdoob/three.js.git MU Yadef /home/dwayne/src/github.com/zzuegg/Yadef origin [email protected]:zzuegg/Yadef.git MU dmonkey /home/dwayne/src/github.com/kwando/dmonkey origin https://github.com/kwando/dmonkey.git MU getdown /home/dwayne/src/github.com/threerings/getdown origin https://github.com/threerings/getdown.git dart-protoc-plugin /home/dwayne/src/github.com/dart-lang/dart-protoc-plugin origin [email protected]:dart-lang/dart-protoc-plugin.git M vdrones /home/dwayne/src/github.com/davidB/vdrones origin [email protected]:davidB/vdrones.git shader_editor /home/dwayne/src/github.com/davidB/shader_editor origin [email protected]:davidB/shader_editor.git scala-maven-plugin /home/dwayne/src/github.com/davidB/scala-maven-plugin origin [email protected]:davidB/scala-maven-plugin.git simpleaudio /home/dwayne/src/github.com/davidB/simpleaudio origin [email protected]:davidB/simpleaudio.git MU ld31_p0cm0n /home/dwayne/src/github.com/davidB/ld31_p0cm0n origin [email protected]:davidB/ld31_p0cm0n.git livereload-jvm /home/dwayne/src/github.com/davidB/livereload-jvm origin [email protected]:davidB/livereload-jvm.git dart-protobuf /home/dwayne/src/github.com/davidB/dart-protobuf origin [email protected]:davidB/dart-protobuf.git U jme3_skel /home/dwayne/src/github.com/davidB/jme3_skel origin [email protected]:davidB/jme3_skel.git asset_pack /home/dwayne/src/github.com/davidB/asset_pack origin [email protected]:davidB/asset_pack.git git-find /home/dwayne/src/github.com/davidB/git-find origin [email protected]:davidB/git-find.git jme3_ext_assettools /home/dwayne/src/github.com/davidB/jme3_ext_assettools origin [email protected]:davidB/jme3_ext_assettools.git ...
-
向所有仓库广播
git status
git find -t 'cd {{ .path.full }}; echo "\n\n----\n$PWD"; git status' | sh
-
清理 Git 仓库(以释放空间)
git find -t 'cd {{ .path.full }} && git clean -d -X -f' | sh
模板格式
模板格式是 golang text/template 的子集。
可能的值
!! 实验:值可能会随着未来版本发布而更改 !!
- .path
- .file_name
- .full
- .remotes
- .<name_of_remote>:例如 'origin'
- .name
- .url_full
- .url_host
- .url_path
- .<name_of_remote>:例如 'origin'
- .working_paths
- .conflicted:路径列表
- .modified:路径列表
- .added:路径列表
- .deleted:路径列表
- .renamed:路径列表
- .untracked:路径列表
用于脚本
- 在您的脚本中显式使用模板(默认模板可能会随着每个版本发布而更改)
- 如果模板是 shell 脚本(提示可以用于任何解释器:python、ruby 等),则可以
# run it directly
git find -t '...' | sh
# generate a script and run it later (maybe after review)
git find -t '...' > myscript.sh
sh myscript.sh
示例
-
列出本地仓库
{{ .path.file_name }}\t{{ .path.full }}
-
列出具有 origin URL 的本地仓库
{{ .path.file_name }}\t{{ .path.full }}\t{{with .remotes.origin}} {{ .name }} {{.url_full}} {{.url_host}} {{.url_path}} {{end}}
-
创建一个 sh 脚本来在所有仓库上执行 "git fetch"
cd {{ .path.full }}; echo "\n\n---------------------------------------------\n$PWD"; git fetch
-
创建一个 sh 脚本来将 Git 仓库移动到 $HOME/src(与 go 工作区相同的布局)
echo "\n\n---------------------------------------------\n" PRJ_SRC="{{ .path.full }}" {{if .remotes.origin}} PRJ_DST="$HOME/src/{{ .remotes.origin.url_host }}/{{ .remotes.origin.url_path}}" {{else}} PRJ_DST=$HOME/src/_local_/{{ .path.file_name}} {{end}} if [ ! -d "$PRJ_DST" ] ; then read -p "move $PRJ_SRC to $PRJ_DST ?" answer case $answer in [yY]* ) mkdir -p $(dirname "$PRJ_DST") mv "$PRJ_SRC" "$PRJ_DST" ;; * ) ;; esac fi
-
列出具有一些信息的仓库(0.4.1 版本的默认模板)
{{with .working_paths}}{{if .conflicted}}C{{else}} {{end}}{{if .modified}}M{{else}}{{if .added}}M{{else}}{{if .deleted}}M{{else}}{{if .renamed}}M{{else}} {{end}}{{end}}{{end}}{{end}}{{if .untracked}}U{{else}} {{end}}{{end}}\t{{ .path.file_name }}\t{{ .path.full }}\t{{with .remotes.origin}} {{ .name }} {{.url_full}} {{end}}
安装
从 cargo
使用 Rust 的包管理器 cargo,您可以通过以下方式安装:
cargo install git-find
请注意,需要 rust 版本 1.26.0 或更高版本。
从二进制文件
!! 实验 !!}
发布页面 包含 Linux、macOS 和 Windows 的预编译二进制文件。
- 下载适合您操作系统的存档文件
- 解压缩它,并将可执行文件移动到 PATH
tar -xzvf git-find_0.3.2-x86_64-unknown-linux-gnu.tar.gz
chmod a+x git-find
mv git-find $HOME/bin
rm git-find_0.2.2-linux.tar.gz
从源代码
git clone https://github.com/davidB/git-find
# Build
cd git-find
cargo build
# Run unit tests and integration tests
cargo test
# Install
cargo install
相关和类似工具
一些工具可以帮助管理多个仓库,但功能不完全相同,否则就没有重新做的必要。
信息
- peap/git-global: 跟踪所有您的git仓库。(我快速查看源代码来估算我添加功能的贡献,但“潜在”的变化太多,可能会改变工具的使用目标)
- totten/git-scan: 用于扫描/更新git仓库的CLI工具
- fboender/multi-git-status: 显示多个Git仓库的未提交、未跟踪和未推送的更改
操作(广播)
- gr - 一个用于管理多个git仓库的工具
- mu-repo,一个帮助处理多个git仓库的工具(Multiple Repositories的缩写)。
- mr,这是一个用于管理所有版本控制仓库的工具。
- 仓库命令参考 | Android开源项目
- jiri - Google的Git
- mateodelnorte/meta,将许多仓库转换为元仓库的工具。为什么选择多个仓库或单体仓库,当你可以用元仓库同时拥有两者时?
- nosarthur/gita:为理智地管理多个git仓库而并排排列
待办事项
- 找到一个支持在当前字段(或为gtmpl做出贡献,因为它是go模板的一个特性)上调用方法(获取器)的rust模板引擎
- 内部使用流/队列而不是Vector
- 使用musl构建linux二进制文件(请参阅rust-musl-builder)
- 优化
依赖项
~15–25MB
~426K SLoC