What does “would be overwritten by merge” mean?

前端 未结 3 1931
萌比男神i
萌比男神i 2020-12-20 14:38

When pulling from a team based Git remote repository, I get this message:

\"C:\\Program Files (x86)\\Git\\bin\\git.exe\" pull --progress \"origin\" +refs/hea         


        
3条回答
  •  感情败类
    2020-12-20 14:55

    What rule would produce a "would be overwritten" warning?

    If you've modified a file that also have modifications in the remote repository but have not committed it.

    What rule would avoid a "would be overwritten" warning?

    If there are no uncommitted files that also have modifications in the remote repo.

    What do I need to do...

    It depends on what you actually want:

    1. You want to force a pull to overwrite the file

      Obviously, if you really want this, you don't care about the changes you've just made and don't mind deleting them. If so you simply do:

      git reset --hard
      git pull
      
    2. You want both your changes and the changes from the pull

      The easiest way to handle this in my opinion is to commit your changes then do a pull. Then if there is a merge conflict use the usual mechanisms to resolve the merge (hint: configure your difftool and mergetool so you can easily resolve conflicts using a GUI tool like meld or diffmerge etc.). Just do:

      git add $the_affected_file
      git commit
      git pull
      
    3. You want both changes but you're not ready to commit

      Personally I don't think you should ever be not ready to commit. But it happens from time to time that you have partly broken code that you're debugging and you really don't want to commit. In this case you can stash you changes temporarily then unstash it after pulling:

      git stash
      git pull
      git stash pop
      

      If there are conflicts after popping the stash resolve them in the usual way. Note: you may want to do a git stash apply instead of pop if you're not ready to lose the stashed code due to conflicts.

提交回复
热议问题