git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Stash away the original head in ORIG_HEAD when resetting.

From
Junio C Hamano <junkio@cox.net>
Date
Aug 8, 2005, 06:06 UTC
Message-ID
<7vy87dgdxb.fsf@assigned-by-dhcp.cox.net>

When rewinding the head, stash away the value of the original HEAD in ORIG_HEAD, just like git-resolve-script does.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

Since rewinding the head is a dangerous operation, saving it somewhere just in case would make life a bit safer. This also lets you do:

    $ git commit
    ... "oops, I forgot to include that fix."
    $ git reset HEAD^1
    ... edit away and update-cache
    $ git commit -m ORIG_HEAD
to reuse the old commit message.
 git-reset-script |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
87aced8864d926cf870ddfb2ca7ac5784fccb911
diff --git a/git-reset-script b/git-reset-script
--- a/git-reset-script
+++ b/git-reset-script
@@ -2,6 +2,12 @@
 . git-sh-setup-script || die "Not a git archive"
 rev=$(git-rev-parse --revs-only --verify --default HEAD "$@") || exit
 rev=$(git-rev-parse --revs-only --verify $rev^0) || exit
-git-read-tree --reset "$rev" && echo "$rev" > "$GIT_DIR/HEAD"
+git-read-tree --reset "$rev" && {
+	if orig=$(git-rev-parse --verify HEAD 2>/dev/null)
+	then
+		echo "$orig" >"$GIT_DIR/ORIG_HEAD"
+	fi
+	echo "$rev" > "$GIT_DIR/HEAD"
+}
 git-update-cache --refresh
 rm -f "$GIT_DIR/MERGE_HEAD"
Next: Johannes Schindelin
Message 1 of 4 in “Stash away the original head in ORIG_HEAD when resetting.”
  1. Stash away the original head in ORIG_HEAD when resetting.Junio C Hamano, Aug 8, 2005
  2. Johannes SchindelinAug 8, 2005
  3. Johannes SchindelinAug 8, 2005
  4. Junio C HamanoAug 9, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.