How to solve merge conflicts if I only want to pull files to local server?

StackOverflow https://stackoverflow.com/questions/21114808

  •  28-09-2022
  •  | 
  •  

Вопрос

Following problem: I want to get the files from the git repository to my local test server. But there were many old files on my test server. git pull didn't work and caused that merge conflicts so I tried to delete all my local files and wanted to try it again. But even if the conflicting files doesn't exist anymore the merge conflicts still exist. How to solve them? I tried to display and open the files with git diff --name-only --diff-filter=U vi filename - but I can't solve it that way because the files doesn't exist anymore. Any suggestions?

Это было полезно?

Решение

  1. Information about git conflicts is stored in the index, not the work tree. They are resolved by adding, with git add, the resolved content. It follows that deleting local files won't have any effect.

  2. git pull never generates conflict with local files. It will complain that your work directory is not clean instead. Deleting local files therefore won't help (if you did it before running git pull, it would cause it to complain the working directory is not clean and not do anything).

  3. Therefore the conflict is between the branch that was checked out before and the branch you want to pull.

I suppose you want to have the exact content that you pulled, right? In that case

`git reset --hard origin/master`

should be the fastest way. It tells git to check out the content of the branch master pulled from origin (adjust appropriately if you are using different branch), overwriting any previous content of the working tree, and make the current branch point to that revision.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top