git: 代码分布式版本控制系统
在目录project
对应的终端上
git init # 初始化仓库
django-admin startproject admin_django # 创建django项目
vue init webpack admin_vue # 创建Vue项目
# 添加.gitignore文件
git add . # 添加代码到缓存区
?
git commit -m ‘项目初始化‘ # 提交改变的代码
查看所有分支
git branch # 当前所在的分支名前,会有一个 *
?
* master
创建新分支
git branch test # 创建新分支
切换分支,
git checkout test # 注意:分支test需要先创建,才能切换
?
?
git checkout -b test2 # 创建并切换到新分支test2
合并分支
git checkout master # 切换到分支master
?
git merge test # 合并test分支到主分支
删除分支
git branch -d test
代码冲突
master 分支
test分支 在没有同步 master的时候,也修改 1.txt 文件,添加、提交
最后,在master分支, 合并test分支时,会出现 代码冲突
$ git merge test
Auto-merging 1000.html
CONFLICT (content): Merge conflict in 1000.html
Automatic merge failed; fix conflicts and then commit the result.
?
$ git add .
$ git commit -m ‘代码冲 突‘
[master 95741e6] 代码冲突
?
$ vi 1000.html # 修改1.txt,解决冲突
$ git add .
$ git commit -m ‘解决代码冲 突‘
[master 84e6f78] 解决代码冲突
1 file changed, 4 deletions(-)
原文:https://www.cnblogs.com/lry250/p/14844519.html