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?
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.
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
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
Little B first pulls Little A’s code back, then merges it, and then submits it again.
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
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.
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.
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:
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.
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.
If your code modifications are small, you can copy a copy and paste it in.