11/24/2023 0 Comments Abort git stash pop![]() ![]() I've run through it with a simple example and it gets you back to where you want to be - directly before the stash was popped, with your local changes and with the stash still being available to pop. This can be done with the following command: git stash show -p | git apply -Rĥ) Commit these changes: git commit -a -m "reversed patch"Ħ) Get rid of the patch/unpatch commits git rebase -i HEAD^^^įrom this, remove the two lines with 'merge' and 'reversed patch' in it.ħ) Get your unstanged changes back and undo the 'local changes' commit git reset HEAD^ Now commit your unstaged changes git add. git commit -m "merge"ģ) Now you will still have your local unstaged changes that you started originally, with a new commit from the patch (we can get rid of this later). Give it a commit message of "merge" or something you remember. git mergetoolĢ) Commit these changes (they will already be added via the mergetool command). TAKE A BACKUP BEFOREHAND!! I don't know whether this will work for you, so copy your whole repo just in case it doesn't work.ġ) Fix the merge problems and fix all the conflict by selecting all the changes that come from the patch (in tortoisemerge, this shows up as one.REMOETE (theirs)). OK, I think I have managed to find a work-flow that will get you back to where you need to be (as if you had not done the pop). Do you have any repro steps we can follow to help you out? I don't see git trying to merge my changes, it just fails. Please, commit your changes or stash them before you can merge. I am trying to repro your problem but all I get when usin git stash pop is: error: Your local changes to the following files would be overwritten by merge: That should leave your repo in the state it was before (hopefully, I still haven't been able to repro your problem) Then: git stash drop to drop the conflicting stash Git stash show and save that output somewhere if you care about it. Try hardcopying all your repo into a new dir (so you have a copy of it) and run: However, this can fail, when you have conflicts (which are stored in the index, where you therefore can no longer apply the changes as they were originally). If the -index option is used, then tries to reinstate not only the working tree's changes, but also the index's ones. You need to resolve the conflicts by hand and call git stash drop manually afterwards. Your changes will be put back and you can continue what you were doing initially.Edit: From the git help stash documentation in the pop section:Īpplying the state can fail with conflicts in this case, it is not removed from the stash list. ![]() You can now switch back to master $ git checkout masterĭo whatever changes you want on master, and when ready, go back to new-branch. Instead of committing your changes or reverting, you can stash them with: $ git stash save "changes on new-branch" One solution: git stash Stash the changes Git does not allow you to switch back to master because you have changes on new-branch. Please, commit your changes or stash them before you can switch branches. If you want to switch back to master, you will get an error message: $ git checkout masterĮrror: Your local changes to the following files would be overwritten by checkout: On top of that you have some pending changes on new-branch echo change > file1.txt # change file1Įcho change2 > file1.txt # change file1 again Git checkout -b new-branch # create a new branch and switch to that branch Git commit -m "Initial commit" # commit both files If you want to follow along here is the script mkdir testgitstash # create directoryĬd testgitstash # change to that directory We have 2 files: file1.txt and file2.txt and 2 branches, master and new-branch. Well there is a better solution: git stash. You can either commit if you are ready for it, or maybe you have only modified a few lines and can simply revert your changes. Before that happens, you have to take care of all your current changes. You need to switch back to your main dev branch. Common everyday scenario: you are working on your feature branch fixing a bug and your boss asks you for a build.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |