git stash -> merge stashed change with current changes

后端 未结 8 2275
故里飘歌
故里飘歌 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:59

    As suggested by @Brandan, here's what I needed to do to get around

    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
    

    Follow this process:

    git status  # local changes to `file`
    git stash list  # further changes to `file` we want to merge
    git commit -m "WIP" file
    git stash pop
    git commit -m "WIP2" file
    git rebase -i HEAD^^  # I always use interactive rebase -- I'm sure you could do this in a single command with the simplicity of this process -- basically squash HEAD into HEAD^
    # mark the second commit to squash into the first using your EDITOR
    git reset HEAD^
    

    And you'll be left with fully merged local changes to file, ready to do further work/cleanup or make a single good commit. Or, if you know the merged contents of file will be correct, you could write a fitting message and skip git reset HEAD^.

提交回复
热议问题