Git merge file conflict error: Your local changes to the following files would be overwritten by merge

The record about the solution when using git code violations encountered in the project

Question: When I and my colleagues in the same two people change a file he submitted before I submit, this time I will not be submitted, and also does not pull down his code

We will complain:

Your local changes to the following files would be overwritten by merge:

Solution one: git checkout to restore and then pull (that is, covering updates mean)

Solution two: first add then commit the last pull will merge your code locally, no problem and then push the final inspection

------------------------------------------------------------------------------------------------------------------------

Here is a more detailed search to resolve the conflict git article for everyone to share ↓

 

Assuming that conflict file is test / TestCase.php 

  the following points and five cases discussed. 

1, local unchanged. 
  Then there are others remote updates. 
  git pull 
  this simple, there is no conflict, the local workspace directly update 
  
2, my local changes, but do not add. 
Then there are others remote update, then:     
git pull, 
git will tell you: 
error: Your local at The following Changes to Files Would BE overwritten by Merge: 
        Tests / TestCase.php 
  At this point, I  
   git checkout - tests / TestCase.php 
  you should be careful, the command will cause your changes lost!
  Then git pull. Success. 
  In this case, your own changes complete loss. Local accept remote changes. 
  
3, my local changes, but already add up. 
  Then others remote update, 
  git pull 
  this case, almost the same as above. 
  git reset HEAD test / TestCase.php  
  above command can be understood as the inverse command add command. That is, add to cancel the operation. 
  
  Then continue 
  git checkout - tests / TestCase.php 
  should be careful, the command will cause your changes lost!
  Then git pull. Success. 
  In this case, your own changes complete loss. Local accept remote changes. 

    
4, my local modify, add and commit the 
  then others remote update, 
  git pull 
  Note: this case and the second, third case different. git commit will think you are also very important. Equally important. 
Suddenly found automatically enter vi interface. 
Merge branch 'master' of https://github.com/xxxx 
What does this mean? That will help you git will take the initiative to add a commit. 
Notes let you write something, and it has helped you write a few words 
that themselves write something, then save and exit vi 
Please note that this commit is local, not sent to the remote. 
This will automatically merge commit you to the code, and others remote update code, 
so, after this code is at your own check for problems. 

  If there is no problem, then you are now 
  git push 
  command can be pushed to your local changes remotely. 
  After the push, remote, and you get all the updates of others. Before push, only local and you get all the updates of others. 
  
5, using a branch function. 
  git branch function is very powerful, it should be more use. 
  Several conditions above are not using branches. Use branch will be better. 
  First, I create a new local branch and switch branch_1, meaningful name for themselves, and modify the file. 
  Checkout -b branch_1 git 
    
  vi the Test / TestCase.php 
  git Tests the Add / TestCase.php 
  git the commit -m "Change the Test" 
  
  now, someone else has updated the remote master branch code (not updated on the very convenient, do not have to say, fast update) 
  I want to branch into the master branch. 
  I should first return to the main branch, and updates. 
  Checkout Master git 
  git pull 
  
  Then, locally, to amend my branch merge up. 
  git merge branch_1 
  automatically enter vi interface that allows you to write comments. 
  
  Then will merge better. 
  Similar Tip: 
  Tests / TestCase.php | 3 ++ - 
  top, two plus sign indicates that the document adds two lines, a minus sign indicates that the file is reduced row. 
  
  In this case, note that those who enter the vi interface, 
  better yourself and then check procedures, check that the file is prompted modified, (which is a good habit, but I never follow) 
  if deemed proper, finally, 
  git the Push, pushed to the remote. 
  
  After the push, remote, and you get all the updates of others. Before push, only local and you get all the updates of others. 

========== 
summary, in most cases, are recommended fifth, the methods used branches to manage file modification conflict.

Transfer: https://www.iteye.com/blog/xieye-2433229

Guess you like

Origin www.cnblogs.com/bobo1/p/12201156.html