How not to make any changes and a new message?

How to create a new commit and create a new message if no changes are made to the files?

This is not possible since the commit code (SHA?) Will be the same?

+104
git commit
Sep 18
source share
5 answers

There is rarely a good reason for this, but the --allow-empty option for empty --allow-empty-message , unlike --allow-empty-message for empty messages. You can also learn more by typing git help commit or by visiting the online documentation .

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




There are several reasons why you might need an empty commit (including some comments):

  • As a "declarative commit" - add a narration or documentation (via DavidNeiss ), including actual data on passing tests or lint (via Robert Balitsky ).
  • Test git commands without generating arbitrary changes (via Vaelus ).
  • To recreate the remote bare repository, gitolite used (via Tatsh ).
  • Arbitrarily create a new commit, for example, to restart the build tools (via mattLummus ) or for personal registration or metrics (via DynamiteReed ). However, think twice: depending on your branching / merging structure, commits can live very long, so the โ€œjust commit nothingโ€ strategy can inadvertently pollute your team repository with temporary artifacts of the workflow and make it difficult to separate code revisions from ephemeral mess.

Other strategies for adding metadata to the commit tree include:

  • Separate branches or light tags that always indicate a fixation of a certain status (for example, "last committed commit" or "current interim commit").
  • Annotated tags for recording timestamps, commiters, and messages pointing to an existing commit without adding an entry to the commit tree itself.
  • git notes to bind a mutable note on top of an existing immutable commit.
+129
Sep 18
source share

If I understand correctly, you want to make an empty commit. In this case, you need to:

 git commit --allow-empty 
+31
Sep 18
source share

Empty message with message

 git commit --allow-empty -m "Empty test commit" 

Empty commit with empty message

 git commit --allow-empty --allow-empty-message 
+19
Nov 06 '17 at 15:36
source share

Perhaps as a more reasonable alternative, you could create an annotated tag (a named commit with a message). See the git tag -a option.

+2
Sep 18 2018-12-12T00: 00Z
source share

If you use a system like gitversion , it makes sense to do this type of commit. You may have a commit that is specifically designed to iterate over the main version using the comment + semver: major.

+2
Apr 28 '16 at 17:13
source share



All Articles