Skip to content

Git Stash Conflict Resolution

Cleaning up the mess after git stash apply (or pop) results in a merge conflict.

(from ChatGPT):

  1. Resolve Conflicts and Add Changes:

  2. After running git stash pop and encountering conflicts, resolve the conflicts in the affected files.

  3. Once resolved, add these files to the staging area:

    git add <file>
    
  4. Commit the Resolved Changes (Optional but Recommended):

  5. Commit the resolved changes to ensure they are saved in your branch:

    git commit -m "Resolved merge conflicts from stash"
    
  6. Drop the Stash:

  7. Since git stash pop is supposed to apply and then drop the stash, but it doesn't drop it if there are conflicts, you need to manually drop the stash:

    git stash drop
    
  8. This step is crucial. If you don't drop the stash, reapplying it will reintroduce the same changes and potentially cause the same conflicts.

  9. Do Not Reapply the Stash:

  10. After resolving the conflicts and dropping the stash, do not reapply the same stash. The changes from the stash are already incorporated into your branch after resolving the conflicts and committing them.

  11. Proceed with Your Work:

  12. Continue with your work. The resolved changes are now part of your branch, and the stash that caused the conflict has been removed.

By following these steps, you ensure that once a stash is popped and conflicts are resolved, the same stash doesn't get reapplied, preventing the same conflicts from reoccurring.