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?
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 (no files changed), in contrast to --allow-empty-message
for empty commit 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):
git
commands without generating arbitrary changes (via Vaelus).gitolite
(via Tatsh).Other strategies to add metadata to a commit tree include:
git notes
to associate a mutable note on top of an existing immutable commit.commit --amend
if the remote does not allow force pushing. This way you can allow developers to see an important message that goes with the previous commit. –
Caius Empty commit with a message
git commit --allow-empty -m "Empty test commit"
Empty commit with an empty message but you will be asked to type the message
git commit --allow-empty --allow-empty-message
Empty commit with an empty message
git commit --allow-empty --allow-empty-message -m ""
allow-empty-message
flag prompts for commit message. To skip that prompt we can pass empty mess using -m ""
like git commit --allow-empty --allow-empty-message -m ""
–
Guglielmo If I understood you right, you want to make an empty commit. In that case you need:
git commit --allow-empty
If you are using a system like gitversion It makes a lot of sense to do this sort of commit. You could have a commit that is specifically for bumping the major version using a +semver: major comment.
Maybe as a more sensible alternative, you could create an annotated tag (a named commit with a message). See the git tag -a
option.
© 2022 - 2024 — McMap. All rights reserved.
dev
branch formmaster
and then afeat
branch immediately fromdev
, thefeat
branch looks to come from themaster
branch as there is no distinguishing commit on thedev
branch which thefeat
branch comes from. An empty commit when you first make thedev
branch helps establish thedev
branch as it's own indefinitely lasting branch independent ofmaster
. Generally it's helpful when you use branches as layers, and create two layers from a single commit – Gariepy