如果没有对文件进行任何更改,我如何进行新的提交并创建新的消息?
这是不可能的,因为提交的代码(SHA ?)将是相同的?
如果没有对文件进行任何更改,我如何进行新的提交并创建新的消息?
这是不可能的,因为提交的代码(SHA ?)将是相同的?
当前回答
如果你使用的是gitversion这样的系统,执行这种提交是很有意义的。你可以使用+semver: major注释来提交主版本。
其他回答
如果你使用的是gitversion这样的系统,执行这种提交是很有意义的。你可以使用+semver: major注释来提交主版本。
也许作为一种更明智的选择,您可以创建一个带注释的标记(带有消息的命名提交)。参见git标记-a选项。
使用消息空提交
git commit --allow-empty -m "Empty test commit"
使用空消息进行空提交
git commit --allow-empty --allow-empty-message
如果我没理解错的话,你想做一个空洞的承诺。在这种情况下,你需要:
git commit --allow-empty
很少有好的理由这样做,但是参数为——allow-empty表示空提交(没有更改文件),而——allow-empty-message表示空提交消息。你也可以通过输入git help commit或访问在线文档来阅读更多信息。
虽然树对象(它有自己的散列)将是相同的,但提交实际上会有不同的散列,因为它可能会有不同的时间戳和消息,并且肯定会有不同的父提交。所有这三个因素都集成到git的对象哈希算法中。
这里有一些你可能想要空提交的原因(包括一些注释):
As a "declarative commit", to add narration or documentation (via DavidNeiss) including after-the-fact data about passing tests or lint (via Robert Balicki). To test git commands without generating arbitrary changes (via Vaelus). To re-create a deleted bare repository using gitolite (via Tatsh). To arbitrarily create a new commit, such as for re-triggering build tooling (via mattLummus) or for the sake of personal logging or metrics (via DynamiteReed). However, think twice: depending on your branch/merge structure, commits may live for a very long time, so a "just commit nothing" strategy may be inadvertently pollute your team's repository with temporary workflow artifacts and make it hard to separate code revisions from ephemeral cruft.
向提交树中添加元数据的其他策略包括:
分离的分支或轻量级标记总是指向特定状态的提交(例如:“最后接受的提交”或“当前阶段提交”)。 带注释的标签,用于记录时间戳、提交器和消息,指向现有的提交,而无需在提交树本身中添加条目。 Git注释将一个可变注释关联到现有的不可变提交之上。