From 22e407951ef2572c1e68a39364fd3c4b649a3495 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 7 Jul 2008 00:16:38 -0700 Subject: 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 --- git-am.sh | 1 + git-rebase--interactive.sh | 1 + git-rebase.sh | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/git-am.sh b/git-am.sh index 2c517ede59..fe53608c94 100755 --- a/git-am.sh +++ b/git-am.sh @@ -241,6 +241,7 @@ else : >"$dotest/rebasing" else : >"$dotest/applying" + git update-ref ORIG_HEAD HEAD fi fi diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index a64d9d57ab..02d7e3c7b0 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -549,6 +549,7 @@ EOF has_action "$TODO" || die_abort "Nothing to do" + git update-ref ORIG_HEAD $HEAD output git checkout $ONTO && do_rest ;; esac diff --git a/git-rebase.sh b/git-rebase.sh index e2d85eeeab..2597d777d6 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -378,7 +378,7 @@ fi echo "First, rewinding head to replay your work on top of it..." git checkout "$onto^0" >/dev/null 2>&1 || die "could not detach HEAD" -# git reset --hard "$onto^0" +git update-ref ORIG_HEAD $branch # If the $onto is a proper descendant of the tip of the branch, then # we just fast forwarded. -- cgit v1.2.3 From 9869099bee332e4c351c3aaa15a74786d85909c7 Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Tue, 8 Jul 2008 00:12:22 -0400 Subject: Documentation: mention ORIG_HEAD in am, merge, and rebase Merge has always set ORIG_HEAD but never mentioned it, while we recently added it to am and rebase. These facts should be reflected in the documentation. git-reset also sets ORIG_HEAD, but that fact is already mentioned in the very first example so no changes were needed there. Signed-off-by: Brian Gernhardt Signed-off-by: Junio C Hamano --- Documentation/git-am.txt | 6 ++++++ Documentation/git-merge.txt | 4 +++- Documentation/git-rebase.txt | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt index 3863eebcef..88ca5f1183 100644 --- a/Documentation/git-am.txt +++ b/Documentation/git-am.txt @@ -145,6 +145,12 @@ directory exists, so if you decide to start over from scratch, run `rm -f -r .dotest` before running the command with mailbox names. +Before any patches are applied, ORIG_HEAD is set to the tip of the +current branch. This is useful if you have problems with multiple +commits, like running 'git am' on the wrong branch or an error in the +commits that is more easily fixed by changing the mailbox (e.g. +errors in the "From:" lines). + SEE ALSO -------- diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt index 62f99b5f3b..019e4ca8f5 100644 --- a/Documentation/git-merge.txt +++ b/Documentation/git-merge.txt @@ -81,7 +81,9 @@ Otherwise, merge will refuse to do any harm to your repository (that is, it may fetch the objects from remote, and it may even update the local branch used to keep track of the remote branch with `git pull remote rbranch:lbranch`, but your working tree, -`.git/HEAD` pointer and index file are left intact). +`.git/HEAD` pointer and index file are left intact). In addition, +merge always sets `.git/ORIG_HEAD` to the original state of HEAD so +a problematic merge can be removed by using `git reset ORIG_HEAD`. You may have local modifications in the working tree files. In other words, 'git-diff' is allowed to report changes. diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index f3459c7de7..e30f6a6982 100644 --- a/Documentation/git-rebase.txt +++ b/Documentation/git-rebase.txt @@ -26,7 +26,8 @@ of commits that would be shown by `git log ..HEAD`. The current branch is reset to , or if the --onto option was supplied. This has the exact same effect as -`git reset --hard ` (or ). +`git reset --hard ` (or ). ORIG_HEAD is set +to point at the tip of the branch before the reset. The commits that were previously saved into the temporary area are then reapplied to the current branch, one by one, in order. Note that -- cgit v1.2.3