Git自定义子命令

Git subcommands are standalone executables that live in the Git exec path, normally /usr/lib/git-core. The git executable itself is a thin wrapper that knows where the subcommands live, and runs them by passing command-line arguments to them.

(If “git foo” is not found in the Git exec path, the wrapper will look in the rest of your $PATH for it. Thus, it’s possible to write local Git extensions that don’t live in system space.)

可以编写以git-cmdname命名的C、shell、Perl程序(比如git-foo.sh)放在Git的执行路径或$Path中,当使用git cmdname时,Git会查找路径执行相应程序。

也可以通过修改Makefile中的BUILTIN_OBJS,EXTRA_PROGRAMS, SCRIPT_SH, SCRIPT_PERL or SCRIPT_PYTHON选项等操作,将自己的git子命令集成到Git tree中

详见:

new-command.txt

CodingGuidelines

Implementing a new “git …” subcommand as a Python script

Write Your Own Git Subcommands

Extending git

模仿Write Your Own Git Subcommands的一个例子:

$ mkdir ~/subcmd; 
$ touch ~/subcmd/git-custom
$ chmod u+x ~/subcmd/git-custom
$ export PATH="$HOME/subcmd/git-custom:$PATH"

$ git custom.sh
#!/bin/sh

. git-sh-setup
. git-parse-remote
require_work_tree
wt_prefix=$(git rev-parse --show-prefix)
cd_to_toplevel

git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} status

**具体可以参考Git自带的git-subcmd.sh脚本程序

一个可以借鉴的Github项目:tj/git-extras

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值