What is a merge conflict?

杀马特。学长 韩版系。学妹 提交于 2021-01-28 05:11:06

问题


What is merge conflict ?
Most questions out there address resolving merge conflict like this one.

But I have no clue to why its even happening to me...


In short, we were told to:

git clone url ~/lab

Now we had to edit these files and then commit the changes.


For second assignment we need to do the following:

 git commit -am 'changes to lab1 after handin'
 git pull
 git checkout -b lab2 origin/lab2
 git merge lab1

Now my partner sent me his files for lab1. So I can work on his code as it's cleaner and more organized.

git status
>>> nothing to commit, working directory clean

I then delete all files

git status
>>> list of deleted files

git commit -am 'delete my files'
git status
>>> nothing to commit, working directory clean

I then extracted his files to my directory

git status
>>> list of untracked files in red
git add .
git status
>>> Changes to be commit and the list of files in green
git commit -am 'teammate files'
git status
>>> nothing to commit, working directory clean

Now TA commands

git commit -am 'changed branch'
git pull 
>>> Already up-to-data. (As expected!!)
git checkout -b lab2 origin/lab2
>>> On branch lab2 
git merge lab1
>>> almost all files failed merge and have conflict

Any explanation to why is this happening ? and how could I prevent this ? I am afraid to do this on my own as I might remove code which shouldn't be removed... so I'd rather git merge to work on its own.


回答1:


Merge conflict occurs when your changes conflict(will need to overwrite what is on the remote repository, name it master or the branch where you pushing your changes onto) with another person of your team's changes(his changes since last time you pulled would overwrite your changes that you are trying to push, or you will overwrite his changes). Normally you would resolve this conflict by merging. You should be able to see the remote changes, your changes and the outcome. You can select what parts of the code to delete/add/keep.



来源:https://stackoverflow.com/questions/43809309/what-is-a-merge-conflict

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!