@matheusbsbs / matheus-bagliano / commits / 22e407951e
Fork 0

Teach "am" and "rebase" to mark the original position with ORIG_HEAD

"merge" and "reset" leave the original point in history in ORIG_HEAD, which makes it easy to go back to where you were before you inflict a major damage to your history and realize that you do not like the result at all. These days with reflog, we technically do not need to use ORIG_HEAD, but it is a handy way nevertheless. This teaches "am" and "rebase" (all forms --- the vanilla one that uses "am" as its backend, "-m" variant that cherry-picks, and "--interactive") to do the same. The original idea and a partial implementation to do this only for "rebase -m" was by Brian Gernhardt; this extends on his idea. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 7, 2008 at 00:16 UTC 22e407951ef2572c1e68a39364fd3c4b649a3495
3 files changed +3 -1
git-am.sh
+1
@@ -241,6 +241,7 @@ else
241 : >"$dotest/rebasing"
242 else
243 : >"$dotest/applying"
244 + git update-ref ORIG_HEAD HEAD
245 fi
246 fi
247
git-rebase--interactive.sh
+1
@@ -549,6 +549,7 @@ EOF
549 has_action "$TODO" ||
550 die_abort "Nothing to do"
551
552 + git update-ref ORIG_HEAD $HEAD
553 output git checkout $ONTO && do_rest
554 ;;
555 esac
git-rebase.sh
+1 -1
@@ -378,7 +378,7 @@ fi
378 echo "First, rewinding head to replay your work on top of it..."
379 git checkout "$onto^0" >/dev/null 2>&1 ||
380 die "could not detach HEAD"
381 -# git reset --hard "$onto^0"
381 +git update-ref ORIG_HEAD $branch
382
383 # If the $onto is a proper descendant of the tip of the branch, then
384 # we just fast forwarded.