如何提交没有改变和新消息? [英] How to commit no change and new message?

查看:65
本文介绍了如何提交没有改变和新消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果没有对文件进行更改,如何创建新的 commit 并创建新消息?

这是不可能的,因为提交的代码(SHA?)将是相同的?

解决方案

很少有理由做对于空提交,参数是 - allow-empty ,而 - allow-empty-message 为空消息。您还可以通过输入 git help commit 或访问在线文档



尽管树对象(它有自己的散列)将会相同的,提交实际上会有不同的哈希,因为它可能会有不同的时间戳和消息,并且肯定会有不同的父提交。所有这三个因素都集成到 git 的对象散列算法中。





$ b $ 你可能需要一个空的提交(包含一些注释)的几个原因:



  • 作为声明性提交,要添加旁白或文档(通过 DavidNeiss ),包括事后数据通过测试或皮棉(通过 Robert Balicki )。

  • 测试 git 命令,而不会产生任意更改(通过 Vaelus )。
  • >
  • 使用 gitolite 重新创建已删除的裸存储库(通过
  • 任意创建一个新的提交,例如重新触发构建工具(通过 mattLummus )或为了个人记录或指标(通过 BlueJ774 )。然而,请仔细考虑一下:根据分支/合并结构,提交可能会持续很长时间,因此仅提交任何内容策略可能会无意中污染了您的团队存储库中的临时工作流程构件,并且难以将代码修订与


    将元数据添加到提交树的其他策略包括:

  • ul>
  • 单独的分支或轻量级标签总是指向特定状态的提交(例如上次接受的提交或当前分段提交)。
  • 带注释的标记,用于记录时间戳,提交者和消息的方式,指向现有的提交而不在提交树本身中添加条目。

  • git notes 将可变注释关联到现有的不可变提交。

How can I make a new commit and create a new message if no changes are made to files?

Is this not possible since the commit's code (SHA ?) will be the same?

解决方案

There's rarely a good reason to do this, but the parameter is --allow-empty for empty commits, in contrast to --allow-empty-message for empty messages. You can also read more by typing git help commit or visiting the online documentation.

While the tree object (which has a hash of its own) will be identical, the commit will actually have a different hash, because it will presumably have a different timestamp and message, and will definitely have a different parent commit. All three of those factors are integrated into git's object hash algorithm.


There are a few reasons you might want an empty commit (incorporating some of the comments):

  • 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 BlueJ774). 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.

Other strategies to add metadata to a commit tree include:

  • Separate branches or lightweight tags that always point to a commit of a particular status (e.g. "last accepted commit" or "current staging commit").
  • Annotated Tags for a way to record timestamp, committer, and message, pointing to an existing commit without adding an entry in the commit tree itself.
  • git notes to associate a mutable note on top of an existing immutable commit.

这篇关于如何提交没有改变和新消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆