git 提交的开始文本与父提交的文本
Start text of git commit with the text of the parent commit
当您在 git 中创建新提交时,您可以通过指定 git commit -t <filename>
或 [=12] 来指定您希望提交消息编辑器以文件内容启动=] 环境变量。有没有办法指定您始终希望使用父提交的全文作为模板?
上下文:与许多其他代码库一样,我常用的代码库需要注释 bug/issue 提交正在处理的内容,以便出现在每次提交中。记住 bug/issue 个数字很难,而且我经常有一堆关于同一主题的提交,要按顺序提交。使用像git commit; Ctrl+Z; g log -1; <click>; Shift+Ctrl+C; fg; Shift+Ctrl+V
这样的咒语很尴尬,这是我通常被迫做的。
你应该只需要 运行:
git commit -C HEAD --reset-author -e
或更一般地说:
git commit -C $TEMPLATE_COMMIT_SHA1 --reset-author -e
相关联机文档项目为:
https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--Cltcommitgt
-C
--reuse-message=<commit>
Take an existing commit object, and reuse the log message and the
authorship information (including the timestamp) when creating the commit.
https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--e
-e
--edit
The message taken from file with -F, command line with -m, and from commit object with -C are usually used as the commit log message unmodified. This option lets you further edit the message taken from these sources.
以及@KevinReid 的建议:
https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---reset-author
--reset-author
When used with -C/-c/--amend options, or when committing after a conflicting cherry-pick, declare that the authorship of the resulting commit now belongs to the committer. This also renews the author timestamp.
如果你想让这个命令更实用,例如通过依赖环境。变量 TEMPLATE_COMMIT_SHA1
,您可以定义一个 git 别名,例如:
# "committ" stands for "commit-template"
git config alias.committ '!f(){ set -x; git commit -C "${TEMPLATE_COMMIT_SHA1:-HEAD}" --reset-author -e "$@"; }; f'
# or if you prefer to make this alias available for all repos:
git config --global alias.committ '!f(){ set -x; git commit -C "${TEMPLATE_COMMIT_SHA1:-HEAD}" --reset-author -e "$@"; }; f'
# demo
touch a; git add a; git committ
export TEMPLATE_COMMIT_SHA1=HEAD^^^
touch b; git add b; git committ
当您在 git 中创建新提交时,您可以通过指定 git commit -t <filename>
或 [=12] 来指定您希望提交消息编辑器以文件内容启动=] 环境变量。有没有办法指定您始终希望使用父提交的全文作为模板?
上下文:与许多其他代码库一样,我常用的代码库需要注释 bug/issue 提交正在处理的内容,以便出现在每次提交中。记住 bug/issue 个数字很难,而且我经常有一堆关于同一主题的提交,要按顺序提交。使用像git commit; Ctrl+Z; g log -1; <click>; Shift+Ctrl+C; fg; Shift+Ctrl+V
这样的咒语很尴尬,这是我通常被迫做的。
你应该只需要 运行:
git commit -C HEAD --reset-author -e
或更一般地说:
git commit -C $TEMPLATE_COMMIT_SHA1 --reset-author -e
相关联机文档项目为:
https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--Cltcommitgt
-C
--reuse-message=<commit>Take an existing commit object, and reuse the log message and the authorship information (including the timestamp) when creating the commit.
https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--e
-e
--editThe message taken from file with -F, command line with -m, and from commit object with -C are usually used as the commit log message unmodified. This option lets you further edit the message taken from these sources.
以及@KevinReid 的建议:
https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---reset-author
--reset-author
When used with -C/-c/--amend options, or when committing after a conflicting cherry-pick, declare that the authorship of the resulting commit now belongs to the committer. This also renews the author timestamp.
如果你想让这个命令更实用,例如通过依赖环境。变量 TEMPLATE_COMMIT_SHA1
,您可以定义一个 git 别名,例如:
# "committ" stands for "commit-template"
git config alias.committ '!f(){ set -x; git commit -C "${TEMPLATE_COMMIT_SHA1:-HEAD}" --reset-author -e "$@"; }; f'
# or if you prefer to make this alias available for all repos:
git config --global alias.committ '!f(){ set -x; git commit -C "${TEMPLATE_COMMIT_SHA1:-HEAD}" --reset-author -e "$@"; }; f'
# demo
touch a; git add a; git committ
export TEMPLATE_COMMIT_SHA1=HEAD^^^
touch b; git add b; git committ