Git得操作方式

Git

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(-)

 

posted @ 2021-06-03 11:28  憨憨的baby  阅读(46)  评论(0)    收藏  举报