我正在运行--tree-filter
以便将带有历史记录的几个目录移动到另一个目录。我想在提交消息中添加一行,如
(Imported from ProjectA rev 684fa3....)
包括原始项目中相应提交的SHA。
我该怎么做?
答案 0 :(得分:4)
The original sha's available in $GIT_COMMIT
:
git filter-branch --msg-filter 'cat; echo rewritten from $GIT_COMMIT' master
答案 1 :(得分:2)
添加到jthill的answer(git filter-branch --msg-filter 'cat;...'
):
如果是多行提交消息,请确保使用git 2.7+(2015年第4季度)或git 2.4.1-。
commit a5a4b3f见James McCoy (jamessan
)(2015年10月9日)
(Junio C Hamano -- gitster
--在commit 44a9b53中合并,2015年10月20日)
filter-branch
:删除msg过滤器中的多行标题
df06201 (filter-branch
: avoid passing commit message through sed
)
在使用多行标题过滤提交时引入了回归,
如果标题包含空行。
一个例子是gpg签名的提交:
$ git cat-file commit signed-commit
tree 3d4038e029712da9fc59a72afbfcc90418451630
parent 110eac945dc1713b27bdf49e74e5805db66971f0
author A U Thor <author@example.com> 1112912413 -0700
committer C O Mitter <committer@example.com> 1112912413 -0700
gpgsig -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iEYEABECAAYFAlYXADwACgkQE7b1Hs3eQw23CACgldB/InRyDgQwyiFyMMm3zFpj
pUsAnA+f3aMUsd9mNroloSmlOgL6jIMO
=0Hgm
-----END PGP SIGNATURE-----
Adding gpg
因此,“
filter-branch --msg-filter cat
”(应该保持提交消息不变)会溢出签名(在内部空白之后) line)到原始提交消息。