问题描述
是否有一个命令/脚本,它包含提交ID
或文件名
的一个已经提交的提交作为输入,并且改变提交信息而不改变提交ID
?
Is there a command/script which takes the commit ID
or filename
of an already made commit as input, and changes the commit message without changing the commit ID
?
例如 git filter-branch
, git rebase
, git notes
但他们不允许改变单个提交,他们都是互动的。有没有办法以非交互的方式来做到这一点?
I looked into options like git filter-branch
, git rebase
, git notes
but they dont allow change for single commits and they are all interactive. Is there a way to do it non-interactively?
推荐答案
在不更改提交ID的情况下不能更改提交消息,因为提交消息是哈希形成提交ID的数据的一部分。
You cannot change a commit message without changing the commit id because the commit message is part of the data that is hashed to form the commit id.
这就是为什么所有改变单个提交的工具通常会更改所有后续提交( filter-branch
, rebase
等),因为一旦你改变了历史中的一个提交,所有的后代必须改变,因为它们有一个带有新ID的新祖先。
This is why all the tools which change a single commit generally change all the subsequent commits (filter-branch
, rebase
, etc.) because once you change one commit in a history all the descendants must change because they have a new ancestor with a new id.
这篇关于git:如何在不更改提交ID的情况下非交互式地更改已提交的提交消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!