Table of contents
Talk about your understanding of Git?
How do git version conflicts arise?
How to resolve git version conflicts?
3. Submit the modified conflict file
What are the related commands of git?
3. Commands for remote warehouse operations
Talk about your understanding of Git?
First of all, Git is a free, open source distributed version control system that can help us quickly and efficiently handle various projects from small to large.
In development, Git has become a mainstream code hosting technology . Basically, most companies are using Git for multi-person collaborative development, so as to perform version control and branch management on the code . When we operate Git, there are mainly several concepts involved, namely remote warehouse, local warehouse, clone, commit, push, pull, branch, merge, etc.
Remote warehouse: refers to the place where our code is stored on the server. Simply put, it is a code hosting center, which can be said to be the place where the final code is stored. Access is available to everyone on the team.
Local warehouse: refers to a developer's own local warehouse. Everyone has their own local warehouse that only they can access.
Cloning: refers to the process of copying the entire project code from a remote repository to a local repository.
Submitting, pushing, and pulling are the links in Git's working mechanism. They are to submit the code to the local warehouse, and save the modified historical versions in the local warehouse; then push the code to the remote warehouse; before that, if our local code If it is not the latest version, you need to pull the code from the remote warehouse to the local library first. If there is a conflict, you need to resolve the conflict first and then re-push it to the remote library.
And we may encounter multiple branches in development , such as the main branch master, the development branch develop, etc., but generally we will not develop on the main branch, but we will separate one from the main branch or the development branch. Branch, such as the test branch, and then develop code on the test branch. After our development is complete, we need to merge the branch into our main branch. Git version conflicts often occur when merging branches . The reason for the conflicts is that when multiple people collaborate to develop a project, two developers make different content modifications to the same file and the same location, so conflicts occur . The way to resolve the conflict is to manually modify the conflict part ; it can be roughly divided into three steps, which are to find the conflict, modify the conflict, and submit the modified conflict file .
Generally, conflict scenarios will appear in the two links of branch merging and code pulling.
The above is my understanding of Git.
How do git version conflicts arise?
The so-called conflict means that two developers have made different content modifications to the same location of the same file , and then when the branch is merged or the code is pulled from the remote warehouse to the local library, a conflict error will be generated. ; two different versions, causing git to not know which one to accept.
How to resolve git version conflicts?
Manually modify the conflicting files ;
1. Look for conflicts
First of all, you need to find the location where the conflict occurs. If there is a conflict through the git merge branch name, it will prompt those files that have conflicts.
2. Modify the conflict
We can directly find the conflict files in the computer to compare the differences, and then manually modify them to be correct; if we use the command, use cat conflict files to view the differences of different branch codes, and then vim enters the conflict files to delete and modify the correct code.
3. Submit the modified conflict file
Execute the command git add to add to the temporary storage area; git commit -m to submit to the local library; finally git push to push to the remote library.
What are the related commands of git?
1. Common commands
git config --global user.name username | set username
git config --global user.email mailbox | set user mailbox
git init | Initialize the local library
git status | view current status
git add | add to the staging area
git commit -m 'log description' file name | submit to local library
git push alias branch name | push to remote repository
git pull remote library address alias remote branch name | pull remote library content to local library
git reflog | view history
git reset --hard version number | version shuttle
2. Branch command
git branch branch name | create branch
git branch -v | view branch
git checkout branch name | switch branch
git merge branch name | Merge the specified branch into the current branch
3. Commands for remote warehouse operations
git remote add alias remote library ssh address | give remote library address an alias
git remote -v | View all current remote address aliases
git push alias branch | Push the local library to the remote library
git clone remote address | clone the remote library content to the local library
git pull alias branch name | Pull the content of the remote library to the local library