Git branch and merge

One, the master branch Master

First, the code base should have one and only one main branch. All official versions provided to users are released on this master branch.
Insert picture description here

The name of the Git master branch, which is called Master by default . It is created automatically. After the version library is initialized, the development is in the main branch by default.

Two, the development branch Develop

The main branch is only used to distribute major versions, and daily development should be done on another branch. We call the branch for development Develop.
Insert picture description here

This branch can be used to generate the latest overnight version of the code (nightly). If you want to officially release it to the outside world, you can " merge " the Develop branch on the Master branch . Git to create the Develop branch command:

git checkout -b develop master
等同于下面两条:
git branch develop     
git checkout develop

The command to publish the Develop branch to the Master branch:

# 切换到Master分支
git checkout master
# 对Develop分支进行合并
git merge --no-ff develop

What does the -no-ff parameter mean. By default, Git perform " Fast Forward formula merged " (fast-farward merge), Master branch directly to branch point Develop
Insert picture description here

-No-ff way:
Insert picture description here

Three, temporary branch

I mentioned the two main branches of the repository: Master and Develop. The former is used for official release, and the latter is used for daily development. In fact, the permanent branch only needs these two items, and no other items are needed.

However, in addition to the permanent branches, there are also temporary branches for version development for specific purposes. There are three main types of temporary branches:

  • Feature branch
  • Pre-release branch
  • Fix the bug (fixbug) branch

These three branches are temporary needs, and should be deleted after use, so that the permanent branches of the code base are always only Master and Develop.

1. Functional branch

Insert picture description here

The name of the feature branch can be named in the form of feature-*.
Create a feature branch:

git checkout -b feature-x develop

After the development is complete, merge the functional branch into the develop branch:

git checkout develop
git merge --no-ff feature-x

Delete the feature branch:

git branch -d feature-x

2. Pre-release branch

It means that before the official version is released (that is, before merging into the Master branch), we may need to have a pre-release version for testing.

The pre-release branch is separated from the Develop branch. After the pre-release is over, it must be merged into the Develop and Master branches. It can be named in the form of release-*.

Create a pre-release branch:

git checkout -b release-1.2 develop

After confirming that there is no problem, merge to the master branch:

git checkout master
git merge --no-ff release-1.2
# 对合并生成的新节点,做一个标签
git tag -a 1.2

Then merge into the develop branch:

git checkout develop
git merge --no-ff release-1.2

Finally, delete the pre-release branch:

git branch -d release-1.2

Common branch commands:

git branch 分支名 // 新建分支
git branch // 查看当前所有分支
git checkout 分支名 // 检出分支
git checkout -b 分支名 // 创建并切换分支
git checkout commitId 文件名(文件路径下的文件名) 还原这个文件到对应的commitId的版本
(例如src/page/attendance/attendanceSum.vue我想把它还原到2个版本之前 首先git log src/page/attendance/attendanceSum.vue找到对应想要还原的版本
复制版本提交的commitID 然后执行git checkout commitID src/page/attendance/attendanceSum.vue
这样就把attendanceSum.vue这个单个文件 还原到了对应版本)
git branch -v // 查看分支以及提交hash值和commit信息
git branch -d 分支名 // 删除分支
git branch -D 分支名 // 强制删除 若没有其他分支合并就删除 d会提示 D不会
git branch -m 旧分支名 新分支名 // 修改分支名
git branch -M 旧分支名 新分支名 // 修改分支名 M强制修改 若与其他分支有冲突也会创建(慎用)
git branch -r // 列出远程分支(远程所有分支名)
git branch -r -d origin/branch-name  //删除远程分支
git branch -a // 查看远程分支(列出远程分支以及本地分支名)
git fetch // 更新remote索引
git push -u origin 分支名 // 将本地分支推送到origin主机,同时指定origin为默认主机,后面就可以不加任何参数使用git push 也可解决 git建立远程分支//关联时出现fatal ... upstram的问题

Guess you like

Origin blog.csdn.net/weixin_42272869/article/details/113135506