The apply step does a merge of the stashed changes, using Git's powerful underlying merge machinery, the same kind of thing it uses when you do branch merges. (They're still in the repository, and can sometimes be retrieved in an emergency, but for most purposes, you should consider them gone at that point.) This deletes the reference to the weird non-branch-y commits. If all goes well, and you like the results, you should then git stash drop the stash. Switch branches, then "apply" the stash: $ git checkout develop The commits it makes are not "on" anyīranch but are now safely stored in the repository, so you can now This commits your code (yes, it really does make some commits) usingĪ weird non-branch-y method. Run git stash save or git stash push, 1 or just plain git stash which is short for save / push: $ git stash The easiest is probably git stash (as all the other answer-ers If not ( error: Your local changes to the following files would be overwritten. Now you can commit and the new stuff is all on develop. ![]() This creates a new develop branch starting from wherever you are If you don't have a develop yet, the method is trivial: $ git checkout -b develop So now you want these changes, which you have not yet committed to master, to be on develop. return, edit a bunch of stuff, then: oops, wanted to be on develop Let's take a classic mistake: $ git checkout master Resolve conflicts or abort the merge with git merge -abort.There are a bunch of different ways depending on how far along you are and which branch(es) you want them on. 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 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. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |