From: Oleg Broytman Date: Mon, 29 Jun 2015 19:24:12 +0000 (+0300) Subject: Example of git reflog + git reset + git cherry-pick X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;ds=sidebyside;h=3556dfe5b297676bfa134f82dcbfa5af86fc7e6e;p=git-wiki.git Example of git reflog + git reset + git cherry-pick --- 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 ---------------------------