git stash blunder: git stash pop and ended up with merge conflicts

后端 未结 4 1792
滥情空心
滥情空心 2020-12-12 11:16

I did a git stash pop and ended up with merge conflicts. I removed the files from the file system and did a git checkout as shown below, but it thi

4条回答
  •  隐瞒了意图╮
    2020-12-12 11:17

    See man git merge (HOW TO RESOLVE CONFLICTS):

    After seeing a conflict, you can do two things:

    • Decide not to merge. The only clean-ups you need are to reset the index file to the HEAD commit to reverse 2. and to clean up working tree changes made by 2. and 3.; git-reset --hard can be used for this.

    • Resolve the conflicts. Git will mark the conflicts in the working tree. Edit the files into shape and git add them to the index. Use git commit to seal the deal.

    And under TRUE MERGE (to see what 2. and 3. refers to):

    When it is not obvious how to reconcile the changes, the following happens:

    1. The HEAD pointer stays the same.

    2. The MERGE_HEAD ref is set to point to the other branch head.

    3. Paths that merged cleanly are updated both in the index file and in your working tree.

    4. ...

    So: use git reset --hard if you want to remove the stash changes from your working tree, or git reset if you want to just clean up the index and leave the conflicts in your working tree to merge by hand.

    Under man git stash (OPTIONS, pop) you can read in addition:

    Applying the state can fail with conflicts; in this case, it is not removed from the stash list. You need to resolve the conflicts by hand and call git stash drop manually afterwards.

提交回复
热议问题