From 3556dfe5b297676bfa134f82dcbfa5af86fc7e6e Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 29 Jun 2015 22:24:12 +0300 Subject: [PATCH] Example of git reflog + git reset + git cherry-pick --- pep-git.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pep-git.txt b/pep-git.txt index a8be119..b2e3038 100644 --- a/pep-git.txt +++ b/pep-git.txt @@ -467,6 +467,18 @@ reflog``, verify it with ``git show`` or ``git log`` and run ``git reset $COMMIT_ID``. Git stores the move of the branch's head in reflog, so you can undo that undo later again. +In a more complex situation you'd want to move some commits along with +resetting the head of the branch. Cherry-pick them to the new branch. +For example, if you want to reset the branch ``v2`` back to the +original commit but preserve two commits created in the current branch +do something like:: + + $ git branch save-v2 # create a new branch saving v2 + $ git reflog # find the original place of v2 + $ git reset $COMMIT_ID + $ git cherry-pick save-v2~ save-v2 + $ git branch -D save-v2 # remove temporary branch + git revert: revert a commit --------------------------- -- 2.39.2