commit: preserve commit hash on a no-op amend#2334
Open
HaraldNordgren wants to merge 2 commits into
Open
Conversation
e049e8d to
faa4b57
Compare
90de46c to
a8e5e5f
Compare
A later change adds a second caller that commits the index lock and dies on failure, so wrap that into a helper to avoid duplicating its message. No functional change intended. Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
74577b7 to
28ce025
Compare
ca4bf1b to
b932927
Compare
"git commit --amend --no-edit" reset the committer date to "now" and rewrote the commit even when nothing else changed, moving the branch tip to a new hash for an effective no-op. Build the amended commit reusing the existing committer date: if that reproduces the current commit, leave the branch alone, report "nothing to amend", and skip the reflog entry and the post-commit and post-rewrite hooks. Signing always rewrites the commit, since its signature cannot reproduce the original, so it skips this detection. Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
b932927 to
44be2f9
Compare
Contributor
Author
|
/submit |
|
Submitted as pull.2334.git.git.1781342189.gitgitgadget@gmail.com To fetch this version into To fetch this version to local tag |
|
Johannes Sixt wrote on the Git mailing list (how to reply to this email): Am 13.06.26 um 11:16 schrieb Harald Nordgren via GitGitGadget:
> git commit --amend --no-edit rewrote the commit and moved the branch tip
> even when nothing changed, because the committer date was reset to "now".
> Reuse the existing committer date so a no-op amend keeps the commit hash and
> leaves the branch untouched.
`git commit --amend --no-edit` is a way to set the committer timestamp
to the current time without changing other aspects of the commit. This
takes away this ability, doesn't it?
Is this keyed to --no-edit? Why is this mode special? Wouldn't it be an
identical case when the commit message is passed to the editor, but
comes back unchanged?
An invocation of `git commit` asks to "please make a new commit". But in
the suggested mode, no new commit is created. Shouldn't this then be
regarded as failure?
What happens with the current branch? Is it left unchanged (no ref
update occurs) or is it changed (a ref update occurs, but it happens to
be a no-op)? And does this then generate a reflog entry?
The updated documentation says about signed commits (note: I am totally
clueless about commit signing procedures):
> A commit that is being signed (`-S`, or `commit.gpgsign`)
> is always rewritten, since its signature cannot reproduce the original.
But if the commit doesn't change in any way, why should the signature be
invalidated, rewritten, or updated?
-- Hannes
|
|
User |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
git commit --amend --no-editrewrote the commit and moved the branchtip even when nothing changed, because the committer date was reset to
"now". Reuse the existing committer date so a no-op amend keeps the
commit hash and leaves the branch untouched.
A real change (tree, message, author, committer, or signing) still
rewrites as before.
cc: Johannes Sixt j6t@kdbg.org