Undo a commit, then re-merge, in git? -


oops, i'd undo merge.

i made new branch, new_branch. did work on branch, , (in order have backup on file sync) checked in temporary commit.

then went master branch, , made 12 commits.

then went new_branch, , without thinking, ran:

git merge master 

now history on branch looks this:

- master commit 1 - master commit 2 - master commit 3 ... - work in progress 

i'd un-merge master, undo work in progress commit, re-merge master. i'd end history on branch looks instead:

- master commit 1 - master commit 2 - master commit 3 ... - master commit 12  

and instead of 'work in progress' commit, have bunch of changed files in staging.

is possible? if so, how?

if understand correctly, new_branch code has been effected? , not wish keep work-in-progress code? , want new_branch fresh copy of latest of master?

in case, deleting branch , recreating might simple solution...

but let's answer question, in case misunderstood or you're interested.

in general, reset commit need find commit right before 1 you'd undo. in case, assume master commit 12.

then run git reset --hard master_commit_12_sha

if don't want have find sha (the series of numbers identifies commit), can count backwards head.

git reset --hard head~1

now, don't think asking this, if problem this:

  • master commit 1
  • master commit 2
  • mistake_commit
  • master commit 3 ...
  • master commit 12

in case, can either:

  • git rebase -i <master commit 2>^, in interactive rebase chose "remove" mistake_commit.
  • git revert mistake_commit, make new commit undoes changes make in mistake_commit. note: option may best if pushed origin, since not change history.

here links read said:


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -