Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [FIXED PATCH] Make rebase save ORIG_HEAD if changing current branch

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:44:54
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)

Junio C Hamano [off-list ref] writes:
Brian Gernhardt [off-list ref] writes:
quoted
My final thought is that the rational ORIG_HEAD and when we set it is
not clearly documented anywhere.  But I am currently out of time to
work on git, so that patch won't be coming from me soon.
The idea behind ORIG_HEAD is to have an anchoring point before an
operation that moves your HEAD in a drastic way.  Think if it as a
poor-man's reflog -- in fact it predates reflog.

That is why reset saves away the HEAD before it does its thing, so that
you can easily say "Oops, I did not mean it -- reset ORIG_HEAD" to flip
back to the previous state.  Both a fast-forward merge and a real merge
can be undone by resetting back to ORIG_HEAD.

So in that sense:

 (1) ORIG_HEAD is not strictly necessary these days, because we have
     reflogs;

 (2) Even then, it is handy and useful, and we could add ORIG_HEAD to more
     commands such as "git am" and "git rebase".
Perhaps something like this for "git am" (only minimally tested).

-- >8 --
am: record ORIG_HEAD so that we can quickly undo a large series

This teaches "git-am" to record the commit before it starts its work in
ORIG_HEAD, so that application of a large series can be undone by
resetting to it.

Signed-off-by: Junio C Hamano <redacted>
---
 git-am.sh |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/git-am.sh b/git-am.sh
index 2c517ed..818b4e5 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -242,6 +242,7 @@ else
 	else
 		: >"$dotest/applying"
 	fi
+	git update-ref ORIG_HEAD HEAD
 fi
 
 case "$resolved" in
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help