![]() Resolve conflicts or abort the merge with git merge -abort. The recovery is same as described in Conflict resolution. Git pull can create a conflict since git pull always also includes a git merge (more about this Recovering from conflict after git pull But sometimes we run this command on the wrong branch.Ĭheck with git log the commit hash that you would like to rewind the Git merge, git rebase, and git pull modify the current branch, never Recovering from merging/pulling into the wrong branch Ĭheck with git log or git graph that both branches point to the same, latest, commit. Solution 2 using git reset –hard (makes sense if the correct branch shouldĬontain all commits of the accidentally modified branch):Ĭreate the correct branch, pointing at the latest commit: git branch. Rewind the branch that accidentally got wrong commits with git reset -hard (see also above). Cherry-pick all commits that should have gone to the correct Git cherry-pick can be used to take a specific commit to theĬurrent branch. Make sure toĬreate it from the commit hash where you wish you had created it from: git branch Make sure that the correct branch exists and if not, create it. Here we assume that we made a couple of commits but we realize they went to the It is easy to forget to create a branch or to create it and forget to switch to Recovering from committing to the wrong branch ![]() HEAD is now at dd4472c we should not forget to enjoy $ git log -onelineĭd4472c (HEAD -> master) we should not forget to enjoy 2bb9bb4 add half an onion 2d79e7e adding ingredients and instructions Undoing Commits & Changes git checkout git clean git revert git reset git rm In this section, we will discuss the available undo Git strategies and commands. D62ad3e (HEAD -> master) Revert "not sure this is a good idea" f960dd3 not sure this is a good idea dd4472c we should not forget to enjoy 2bb9bb4 add half an onion 2d79e7e adding ingredients and instructions $ git reset -hard dd4472c
0 Comments
Leave a Reply. |