Before learning about git, let's take a look at some basic concepts of git.
I am a junior in a Bachelor's college and have my own student team. in project development, I used Git technology to improve development efficiency. Now, Let's summarize git. You are welcome to communicate with each other.
Before learning about git, let's take a look at some basic concepts of git.
1. for git workflow, see
|-Master (master branch, synchronized with online code)
|-Develop)
|-Feature (temporary branch (function branch). For example, you can create a new feature branch by developing a function, and then merge the feature branch to develop)
| --- Feature/update_online_pay_api
| --- Feature/add_new_feature ..
| ---...
|-Release)
| --- Release/update_online_pay_api
| ---...
|-Hotfix)
| --- Hotfix/handler_pay_bug
| ---...
About the branch naming rules: known as the name, the temporary branch can be separated by '/', or '-', without mandatory requirements.
The git process is as follows:
First, you need to synchronize the projects in the remote git repository to your local machine. The process is as follows:
Cd ~ /Workspace/git // enter your personal working directory mkdir project_name // create a directory to store code, the name can be the same as the remote repository name cd project_name // Enter your new directory git init // use git to initialize this directory as a git repository git remote add origin git@github.com: 22th/oh-my-zsh.git // associate the local repository to a remote repository git fetch -- depth = 1 // update some information about the remote repository to the local, for example, git checkout-B master origin/master. // Check out a branch master and associate it with the remote master branch git pull. // update the local repository code.
Through the above process, you can synchronize the remote project to the local machine. now the default is the remote master branch. you cannot modify the code in the master branch. Generally, you do not have this permission. After the code is synchronized to the local machine, you need to create a new development branch based on your business needs and adjust the name based on your needs. for example, you need to develop a new function, create a feature-xxx branch. if you solve a bug, you can create a hotfix-xxx branch. It is not recommended to create a new branch locally. you should create a new branch from the git repository management background and check it locally. It's easy to create a branch in the management background.
Then you can check the new branch to the local machine. the command is as follows:git checkout -b feature-xxx origin/feature-xxx
The next step is your pleasant development process. you can develop, test, and submit your own branch. the following git commands will be used:
Git add
// Add the workspace modification to the temporary storage area, add the -- all parameter to add all the modifications to the git commit-m "msg" in the temporary storage area. // add the modifications to the version Library git push-u origin feature-xxx // push the changes in the local repository to the remote git status // view the current working range status git log // view the history commitgit checkout --
// Replace the file git reset -- hard // discard all modifications to the current work interval with the last commit file, and roll back to the previous commit status git checkout
<版本号>
// Roll back to the specified version
To develop functions, you need to test and release them online. The process is as follows:
1. create a new release-xxx branch in the git repository management background based on your feature-xxx branch, which is mainly used for testing.
2. after the release-xxx test is OK, you can send its merge to the master and develop branches. Generally, the merge request is submitted through the git repository management background, wait for the confirmation from the relevant management personnel and merge it to the master. before submitting the merge request, let's take a look at the master branch to ensure that the newly modified code on the master is synchronized with you. When the master node is merged, a conflict may occur. find the conflict file, resolve it, and commit it. The conflict format is as follows:
<<<<<<< HEADln -s ../statics xxx=======ln -s ../statics statics>>>>>>> master
The content between «<HEAD and ====== indicates the code in your branch, while ========and»> master indicates the code in the master branch. The manual conflict resolution process is to confirm the code you want to retain and delete others. that is to say, if you want to keep your local code, it is like this:
<HEAD (delete) ln-s .. /statics xxx (retained) ======= (delete) ln-s .. /statics (delete) >>>>>> master (delete)
Keep the code in the middle of "«<HEAD and ======" OK ".Git commit-am "Conflict Resolution".
3. All right, the other job is handled by the O & M personnel. Generally, after the release-xxx branch test is completed and all conflicts are resolved, the O & M Publisher merge goes to the master branch and then passesgit diff 608e120 4abe32e --name-only | xargs zip update.zipRun the command to package the differential file, and then publish the differential file package. you do not need to overwrite all the files in the online file.
By now, the entire git project development process is very clear. Git also has many advanced functions, such as file comparison, File History modification records, and association with multiple remote repositories. Using git requires flexible use of branches, because the cost of git's new branch switching is very low, because git's new branch does not mean copying the entire directory like svn, then it is processed in more advanced ways such as index files, which is much more efficient.
Recommended git graphical management tools:
Source tree, mac, and windows.
If you liked this article and think others shocould read it, please follow webff
The above is a detailed explanation of Git-the detailed content of the team's rapid development of artifacts. For more details, please pay attention to other related articles in the first PHP community!