Detailed explanation of Git-the team quickly develops artifacts

黄舟
Release: 2023-03-06 19:46:01
Original
1435 people have browsed it


I am a junior student at an undergraduate college. I have my own student team at the school. During project development, in order to improve development efficiency, I used Git technology. Now I’ll summarize git, everyone is welcome to communicate with each other.

Before learning git, let’s first understand some basic concepts of git

##1. The git workflow is shown in the figure below

Detailed explanation of Git-the team quickly develops artifacts

2. Some basic concepts

  • .git directory: generated when using git init to initialize a git warehouse. The git hidden directory stores information such as file change records of the entire project.

  • Workspace: It can be understood as the directory where the local git warehouse is located, which is also the project directory.

  • Staging area: All files added through the git add command are stored in the staging area, which is actually the index file under the .git directory.

  • Repository: that is, the entire git warehouse.

  • The relationship between the three: the workspace is your development directory, all edited files are added to the staging area through git add, and then submitted to the local git warehouse through the git commit command, and then Push to the remote git repository via git push.

The regular git warehouse structure is as follows

git@git.xxx.com:user/project_name.git

|-master (master branch, synchronized with online code)
|-develop (development branch, after the function development is completed, it will be merged into develop first, and then develop will be merged into master)
|-feature (temporary branch (function branch), for example, to develop a certain function, you can create a new feature branch, and merge the feature branch into develop after completion)
|———— feature/update_online_pay_api
|———— feature/add_new_feature..
|———— …
|-release (temporary branch (pre-release branch), after development and testing, create a new release branch for testing, and merge it into master and develop after completion)
|———— release/update_online_pay_api
|———— …
|-hotfix (temporary branch (hot modification branch), generally used for emergency modification of short-term tasks such as bug branches, merged into master and develop after the modification is completed)

|———— hotfix/handler_pay_bug

|————…

About the branch naming rules: Just know the name, temporary branches can be separated by '/' or '-', etc., there is no mandatory requirement.

When you receive a product requirement and start development, the git process is like this:

First you need to synchronize the project in the remote git warehouse to your local. The process is as follows:

cd ~/workspace/git/ // 进入你个人的工作目录
mkdir project_name // 新建一个目录用于存放代码,名称可以和远程仓库名称一样
cd project_name // 进入你新建的目录
git init // 使用git初始化这个目录为一个git仓库
git remote add origin git@github.com:22th/oh-my-zsh.git // 关联本地仓库到一个远程仓库
git fetch --depth=1 // 更新远程仓库的一些信息到本地,比如分支信息等
git checkout -b master origin/master // 检出一个分支master并关联远程的master分支
git pull // 更新本地仓库代码
Copy after login

Through the above process, you can synchronize the remote project to the local one. Now the default is the remote master branch. You cannot modify the code in the master branch. Generally speaking, you do not have this permission. After synchronizing the code to the local, you need to create a new development branch according to business needs. The name can be adjusted to suit your needs. For example, if you want to develop a new feature, then you create a feature-xxx branch. If you want to solve a bug, , you can build a hotfix-xxx branch. It is not recommended to create a new branch locally. You should create a new branch from the git warehouse management background and then check it out locally. Creating a new branch in the management background is very simple, so I won’t go into details.

Then you check your newly created branch locally, the command is as follows:
git checkout -b feature-xxx origin/feature-xxx

The next step is your happy development process , develop, test, and then submit on your own branch. The git commands used are as follows:

git add <file> // 将工作区修改添加到暂存区,加上 --all 参数表示将所有修改添加到暂存区
git commit -m “msg” // 将暂存区的修改添加到版本库
git push -u origin feature-xxx // 将本地仓库中的修改推送到远程
git status // 查看当前工作区间状态
git log // 查看历史commit
git checkout -- <file> // 用最后一次commit的文件替换当前工作区间的文件
git reset --hard // 丢弃工作区间所有修改,回滚到上一个commit状态
git checkout <版本号> // 回滚到指定版本
Copy after login

To develop functions, you need to test and publish them online. The process is as follows

1. Create a new release-xxx branch in the git warehouse management background, based on your feature-xxx branch, mainly for testing.

2. After the release-xxx test is OK, you can merge it into the master and develop branches. Generally, you submit a merge request through the git warehouse management background, wait for confirmation by the relevant management personnel, merge it into the master, and submit the merge request. Before, merge the master branch first to ensure that the newly modified code on the master is synchronized with you. Conflicts may occur when merging master. Find the conflicting files, resolve them and commit. The conflict format is as follows:

<<<<<<< HEADln -s ../statics xxx
=======ln -s ../statics statics
>>>>>>> master
Copy after login

where «««< The content between HEAD and ======= represents the code in your branch, and ======= and »»»> ; master represents the code in the master branch. Then the process of manually resolving conflicts is to confirm the code you want to keep and delete the other

. That is to say, if you want to keep your local code, then it is like this:

保留 «««git commit -am “解决冲突”。
3、好了,其他的工作就是运维人员来处理了。一般是这样的,release-xxx分支测试完成并解决所有冲突后,运维发布人员merge到master分支,然后通过 git d<a href="http://www.php.cn/wiki/109.html" target="_blank">if</a>f 608e120 4abe32e --name-only | xargs zip update.zip 命令打包差异文件,然后发布这个差异文件包就可以啦,不需要所有文件都覆盖线上文件。


到这里,整个git项目开发流程就已经非常清楚了。git还有很多高级功能,比如文件对比、文件历史修改记录、关联多个远程仓库等等需要你慢慢去摸索了。使用git要灵活运用分支,因为git新建切换分支的成本非常低,因为git新建分支不是想svn那样吧整个目录复制一遍,然后通过索引文件等更高级的方式来处理,效率高太多。

在推荐个git图形化管理工具:
source tree, mac和windows都有。


If you liked this article and think others should read it, please follow webff

The above is the detailed content of Detailed explanation of Git-the team quickly develops artifacts. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template