I just started learning git and I have a question.
Both Little A and Little B cloned the latest version from the remote git.
Both people modified the code locally.
Little A submitted the code first.
What will happen if Little B submits the code again?
Will the code submitted by Little A be overwritten or not allowed to be submitted?
伊谢尔伦2017-05-02 09:35:30
Answer the question first:
Little A submitted the code first, and the remote library and the local library of Little A are synchronized, assuming it is 0 -> a
At this time, Little B's local library is 0 -> b. The version of the remote library is newer than the local library. Git will reject the push and report an error.
Git will ask git pull to update the local library, and the pull operation is equivalent to the automatic fetch and merge operations. It will try to automatically merge the remote library into the local library, and then require manual merging when there is a conflict.
漂亮男人2017-05-02 09:35:30
Little B will be prompted to pull the code first. If the line of the code modified by Little B is the same as that of Little A, a conflict will be prompted for that line of the file. It needs to be merged manually. If the modifications are different, Git will automatically merge the relevant codes
PHPz2017-05-02 09:35:30
If you have changed different places, you can merge directly. If you have changed the same place, git will automatically put the two versions of the code into the file for you to choose
迷茫2017-05-02 09:35:30
Little B first pulls Little A’s code back, then merges it, and then submits it again.
phpcn_u15822017-05-02 09:35:30
After each development is completed, first add commit and then pull the remote code. If there is any conflict, resolve it as soon as possible and then push it. Of course, I am talking about not considering branches
淡淡烟草味2017-05-02 09:35:30
There is a habit, which I think sounds good, that is, every time you submit code, you should pull first and then push. This will avoid errors to a large extent. As for resolving conflicts, this is a problem with the code. After an error is reported, the file will be displayed in red. , there is a dividing line, the top is other people's code, the bottom is your own code, choose according to needs.
高洛峰2017-05-02 09:35:30
I got drunk when I saw the title. Since it is a conflict, it must be resolved manually.
The tool cannot determine how to merge the codes, so there will be conflicts. If Git could resolve conflicts by itself, there would be no need for people to write code.
習慣沉默2017-05-02 09:35:30
When submitting the code, Xiao B should first git pull to update the code. If there is a conflict in the code, an error similar to this will appear:
error: Your local changes to the following files would be overwritten by merge:
****/****/**.php
Please, commit your changes or stash them before you can merge.
At this time, git requires you to manually modify the conflict first, find the prompted file, and """" will appear in the conflicting part to separate the parts of the code that need to be modified. Which part needs to be modified depends on how you choose.
大家讲道理2017-05-02 09:35:30
Git will not resolve conflicts by itself, it will only try to merge patches. If git finds that two patches have modified the same content, it will actively use <<<<<< >>>> >>>> to display conflicts and then resolve them later.
我想大声告诉你2017-05-02 09:35:30
If your code modifications are small, you can copy a copy and paste it in.