如何使命令与“类似”;git rebase-i“;

如何使命令与“类似”;git rebase-i“;,git,Git,我正在尝试为git编写一个自定义命令。我希望它的行为类似于git-rebase-I,其中一个文件在VIM中打开,写入+退出该文件将触发更多代码 我所指的例子 运行git rebase-i时,将打开此文件: noop # Rebase 3ffddbe..3ffddbe onto 3ffddbe (1 command(s)) # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit mess

我正在尝试为
git
编写一个自定义命令。我希望它的行为类似于
git-rebase-I
,其中一个文件在VIM中打开,写入+退出该文件将触发更多代码

我所指的例子

运行
git rebase-i
时,将打开此文件:

noop

# Rebase 3ffddbe..3ffddbe onto 3ffddbe (1 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
通常那里有提交散列,您可以挤压或其他方式。我想要类似的东西,我可以运行我的自定义
git-edmund
命令,它将在一个文件中打开结果

所以我的目标是:

1) 吉特·埃德蒙

2) 编辑打开的文件。我希望内容看起来像这样(基本上是git log-n3--pretty=format:“%H%cN”的结果):


3) 运行解析该文件的代码

创建脚本名git edmund,将其放置在
$PATH
中的某个位置,并确保其可执行。脚本可能应该做一些类似于

#!/bin/sh
tmpfile=$(mktemp gitXXXXXX)
trap "rm -f $tmpfile" EXIT
git log -n 3 --pretty=format:"%H %cN" > $tmpfile
${VISUAL:-${EDITOR:-vi}} $tmpfile
...do stuff with $tmpfile here...

现在,当您运行
git-edmund
时,它将运行您的
git-edmund
脚本,您可以在其中执行所需的任何逻辑。

创建脚本名称
git-edmund
,将其放置在
$PATH
中的某个位置,并确保其可执行。脚本可能应该做一些类似于

#!/bin/sh
tmpfile=$(mktemp gitXXXXXX)
trap "rm -f $tmpfile" EXIT
git log -n 3 --pretty=format:"%H %cN" > $tmpfile
${VISUAL:-${EDITOR:-vi}} $tmpfile
...do stuff with $tmpfile here...

现在,当您运行
git-edmund
时,它将运行您的
git-edmund
脚本,您可以在其中执行所需的任何逻辑。

您可以做的是使用自定义shell函数创建您自己的git。它可能看起来像这样:

[alias]    
edmund = "!ed() { git log -n 3 --pretty=format:\"%H %cN\" | vim - ; }; ed"

因此,当您执行git edmund时,它将打开带有3个最新提交的vim编辑器。这不是你想要的行为,但是你可以从它开始并改进它。我希望有帮助

您可以做的是使用自定义shell函数创建自己的git。它可能看起来像这样:

[alias]    
edmund = "!ed() { git log -n 3 --pretty=format:\"%H %cN\" | vim - ; }; ed"

因此,当您执行git edmund时,它将打开带有3个最新提交的vim编辑器。这不是你想要的行为,但是你可以从它开始并改进它。我希望有帮助

不是写的那样,但是很明显,您可以修改调用编辑器的行,使其同时询问
git config
该信息。不是写的那样,但是显然您可以修改调用编辑器的行,使其同时询问
git config
该信息。