How to make git merge handle uncommitted changes to my working tree?

后端 未结 4 1709
深忆病人
深忆病人 2021-01-30 13:06

A co-worker and I are both working on the master branch at the moment. I have some code in my working tree that I don\'t want to commit (debugging statements and the like). No

4条回答
  •  孤独总比滥情好
    2021-01-30 13:21

    • If local work is uncommitted
      • And you've introduced completely new files that don’t exist in the remote branch:
      • Or the files affected by your local work have ZERO overlap with the files affected by the changes you need to pull from the remote:
        • You're in luck: git pull will "just work"
      • Otherwise:
        • If your local changes have NO overlap with changes you are pulling:
          • git stash will work:
            • git stash save
            • git pull
            • git stash pop
        • If your local changes have SOME overlap with changes you are pulling:
          • git stash will require manual conflict resolution:
            • git stash save
            • git pull
            • git stash pop
            • resolve merge conflicts
            • git reset
            • git stash drop
    • If local work is committed
      • And the files affected by your local work have ZERO overlap with the files affected by
        • You're in luck: git pull will "just work"
        • However: git pull --rebase will "work even better" because of a cleaner history
        • there is no merge commit; your changes will be committed after upstream changes
      • Otherwise:
        • git pull will require manual conflict resolution:
          • git pull
          • resolve merge conflicts
          • git add FILE for each conflicting FILE
          • git commit
        • git pull --rebase could still "work even better" because of a cleaner history
          • however, resolving merge conflicts could be much harder

    For a detailed explanation, please see: https://happygitwithr.com/pull-tricky.html

提交回复
热议问题