From: Pushkar Singh <pushkarkumarsingh1970@gmail.com>
To: git@vger.kernel.org
Cc: peff@peff.net, gitster@pobox.com,
Pushkar Singh <pushkarkumarsingh1970@gmail.com>
Subject: [PATCH] reset: avoid reflog update on no-op reset
Date: Thu, 22 Jan 2026 15:47:45 +0000 [thread overview]
Message-ID: <20260122154743.20496-3-pushkarkumarsingh1970@gmail.com> (raw)
When "git reset" is invoked with a target that already matches HEAD,
it currently writes a reflog entry even though no reference is updated.
Detect this no-op case and avoid updating ORIG_HEAD and HEAD, skipping
the reflog entry entirely.
Add a regression test to ensure no reflog entry is written for a no-op
reset.
Signed-off-by: Pushkar Singh <pushkarkumarsingh1970@gmail.com>
---
builtin/reset.c | 4 ++++
t/t1410-reflog.sh | 15 +++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/builtin/reset.c b/builtin/reset.c
index ed35802af1..900c2f2fe8 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -309,6 +309,10 @@ static int reset_refs(const char *rev, const struct object_id *oid)
old_orig = &oid_old_orig;
if (!repo_get_oid(the_repository, "HEAD", &oid_orig)) {
orig = &oid_orig;
+ if (oideq(orig, oid)) {
+ strbuf_release(&msg);
+ return 0;
+ }
set_reflog_message(&msg, "updating ORIG_HEAD", NULL);
refs_update_ref(get_main_ref_store(the_repository), msg.buf,
"ORIG_HEAD", orig, old_orig, 0,
diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh
index ce71f9a30a..54f8692c53 100755
--- a/t/t1410-reflog.sh
+++ b/t/t1410-reflog.sh
@@ -533,6 +533,21 @@ test_expect_success 'reflog for symref with unborn target can be listed' '
)
'
+test_expect_success 'reset does not write reflog entry on no-op' '
+ git init no-op-reset &&
+ (
+ cd no-op-reset &&
+ echo a >file &&
+ git add file &&
+ git commit -m initial &&
+
+ before=$(git reflog | wc -l) &&
+ git reset HEAD &&
+ after=$(git reflog | wc -l) &&
+ test "$before" = "$after"
+ )
+'
+
test_expect_success 'reflog with invalid object ID can be listed' '
test_when_finished "rm -rf repo" &&
git init repo &&
--
2.43.0
next reply other threads:[~2026-01-22 15:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-22 15:47 Pushkar Singh [this message]
2026-01-22 18:57 ` [PATCH] reset: avoid reflog update on no-op reset Junio C Hamano
2026-01-22 19:09 ` Jeff King
-- strict thread matches above, loose matches on Subject: below --
2026-01-23 8:54 Pushkar Singh
2026-01-23 16:18 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260122154743.20496-3-pushkarkumarsingh1970@gmail.com \
--to=pushkarkumarsingh1970@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox