git stash -> merge stashed change with current changes

后端 未结 8 2268
故里飘歌
故里飘歌 2020-12-12 13:27

I made some changes to my branch and realized I forgot I had stashed some other necessary changes to said branch. What I want is a way to merge my stashed changes with the

8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 13:37

    Running git stash pop or git stash apply is essentially a merge. You shouldn't have needed to commit your current changes unless the files changed in the stash are also changed in the working copy, in which case you would've seen this error message:

    error: Your local changes to the following files would be overwritten by merge:
           file.txt
    Please, commit your changes or stash them before you can merge.
    Aborting
    

    In that case, you can't apply the stash to your current changes in one step. You can commit the changes, apply the stash, commit again, and squash those two commits using git rebase if you really don't want two commits, but that may be more trouble that it's worth.

提交回复
热议问题