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

你可能感兴趣的:(git)