在提交后的钩子上获取提交消息并重复使用

问题描述 投票:0回答:1

这是我的提交后文件:

#!/bin/sh
unset GIT_INDEX_FILE

git --work-tree=../foo2 --git-dir=/m/Downloads/foo1/.git checkout -f

cd ../foo2/
git add .
git commit -m $1

[在foo1存储库上进行提交时,我需要将已提交的文件移至foo2存储库,并使用相同的提交消息来提交这些文件。

“移动文件”步骤工作正常。我现在的问题是获取提交消息。

git githooks
1个回答
1
投票

您可以通过git show获取提交消息:

git show --no-patch --format=%B

您也可以在提交时使用STDIN作为提交消息:

echo "foo" | git commit --file=-

使用这两位,您应该能够从一个存储库中获取提交消息,并将其用作另一存储库中的提交消息:

git --git-dir=/m/Downloads/foo1/.git show --no-patch --format=%B | git commit --file=-
© www.soinside.com 2019 - 2024. All rights reserved.