我可以使用 Git 以两种方式更改提交历史记录吗?
Can I change the commit history in two ways using Git?
我问这个问题是因为我正在研究 Pro Git 这本书并且有一章 重写历史,这解释了如何更改最后一次提交 $ git commit --amend,更改多个提交消息 $ git rebase -i HEAD~3,使用 $ git filter-branch --tree-filter.
删除所有提交中的特定文件或文件夹
这是我的问题:这本书没有提到通过多次检查所有提交历史来完成这项工作的可能性。所以我移动我的 HEAD,逐个提交,然后我用 $ git commit --amend 一个一个地更改这个特定的提交。
我知道就花费的时间而言真的(真的!)很贵,但它真的可能吗(即有效)?
如果是,在哪些情况下这可能有用?
对于所有次提交,您可以使用newren/git-filter-repo
,它可以重写您需要的任何内容(作者、提交消息、文件或文件内容,...)
例如,关于提交消息,using message-callback:
The message callback is quite similar to the previous three callbacks, though it operates on a bytestring that is likely more than one line:
git-filter-repo --message-callback '
if b"Signed-off-by:" not in message:
message += b"\nSigned-off-by: Me My <self@and.eye>"
return re.sub(b"[Ee]-?[Mm][Aa][Ii][Ll]", b"email", message)'
我问这个问题是因为我正在研究 Pro Git 这本书并且有一章 重写历史,这解释了如何更改最后一次提交 $ git commit --amend,更改多个提交消息 $ git rebase -i HEAD~3,使用 $ git filter-branch --tree-filter.
删除所有提交中的特定文件或文件夹这是我的问题:这本书没有提到通过多次检查所有提交历史来完成这项工作的可能性。所以我移动我的 HEAD,逐个提交,然后我用 $ git commit --amend 一个一个地更改这个特定的提交。
我知道就花费的时间而言真的(真的!)很贵,但它真的可能吗(即有效)?
如果是,在哪些情况下这可能有用?
对于所有次提交,您可以使用newren/git-filter-repo
,它可以重写您需要的任何内容(作者、提交消息、文件或文件内容,...)
例如,关于提交消息,using message-callback:
The message callback is quite similar to the previous three callbacks, though it operates on a bytestring that is likely more than one line:
git-filter-repo --message-callback ' if b"Signed-off-by:" not in message: message += b"\nSigned-off-by: Me My <self@and.eye>" return re.sub(b"[Ee]-?[Mm][Aa][Ii][Ll]", b"email", message)'