【团队开发】git 操作流程

1 创建仓库

创建仓库

得到一个URL

2 git操作

2.1 初始化

初始化仓库

shell 复制代码
git init 

添加origin地址

复制代码
git remote add origin 远程仓库地址

修改origin地址

复制代码
git remote set-url origin <new-url>

运行查看remote命令

shell 复制代码
git remote -v 
shell 复制代码
10321@coderzhao MINGW64 /e/Siemens_projects/code/comfort_engine (master)
$ git remote -v
origin  https://gitee.com/zhaojianfei0820/comfort_-engine.git (fetch)
origin  https://gitee.com/zhaojianfei0820/comfort_-engine.git (push)

2.2 协作开发

主分支创建文件并推送

shell 复制代码
10321@coderzhao MINGW64 /e/Siemens_projects/code/comfort_engine (master)
$ git add .

10321@coderzhao MINGW64 /e/Siemens_projects/code/comfort_engine (master)
$ git commit -m "master add test&readme"
[master (root-commit) bdeda1a] master add test&readme
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 ReadMe.txt
 create mode 100644 Test/test.py


10321@coderzhao MINGW64 /e/Siemens_projects/code/comfort_engine (master)
$ git push origin master
10Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 16 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 292 bytes | 292.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/zhaojianfei0820/comfort_-engine.git
 * [new branch]      master -> master

创建新的开发分支

shell 复制代码
git branch <new branch name>

创建新分支并切换到该分支

shell 复制代码
git checkout -b <new branch name>

查看所有的分支

shell 复制代码
git branch

将本地创建的分支推送到远程分支

shell 复制代码
git push origin <branch name>

在当前分支创建一个新的分支后,新创建的分支会复制当前分支的所有代码

2.3 邀请同事协作开发

可以在gitee中发送邀请。

协同开发

创建三个分支,分别是:

  • master
  • feature/zhao
  • feature/x

master分支做为主分支,feature/zhao开发功能A,feature/x开发功能B

开发者A 在feature/zhao上面开发

git add.

git commit -m ""

git push origin feature/zhao

开发者B在feature/x上面开发

git add .

git commit -m ""

git push origin feature/x

master合并代码

切换到master分支

shell 复制代码
git checkout master 

合并feature/zhao分支的代码

shell 复制代码
git merge feature/zhao

合并feature/x分支的代码

shell 复制代码
git merge feature/x

2.4 merge操作的常见问题

在master分支创建一个bug.txt文件

shell 复制代码
10321@coderzhao MINGW64 /e/Siemens_projects/code/comfort_engine (master)
$ touch bug.txt

10321@coderzhao MINGW64 /e/Siemens_projects/code/comfort_engine (master)
$ vim bug.txt

bug.txt文件是:

txt 复制代码
10321@coderzhao MINGW64 /e/Siemens_projects/code/comfort_engine (master)
$ cat bug.txt
第一行:bug file 2023-12-05
第二行:bug file 2023-12-05

基于master分支创建一个hotfix分支,用于bug修复

shell 复制代码
git checkout -b hotfix

在hotfix分支修改bug.txt文件

txt 复制代码
10321@coderzhao MINGW64 /e/Siemens_projects/code/comfort_engine (hotfix)
$ vim bug.txt

10321@coderzhao MINGW64 /e/Siemens_projects/code/comfort_engine (hotfix)
$ cat bug.txt
bug file 2023-12-05
bug file 2023-12-12
success

开始合并分支

合并之前先返回master

shell 复制代码
git checkout master

触发合并

shell 复制代码
git merge hotfix
shell 复制代码
10321@coderzhao MINGW64 /e/Siemens_projects/code/comfort_engine (master)
$ git merge fixhot2
CONFLICT (modify/delete): bug.txt deleted in HEAD and modified in fixhot2.  Version fixhot2 of bug.txt left in tree.
Automatic merge failed; fix conflicts and then commit the result.

10321@coderzhao MINGW64 /e/Siemens_projects/code/comfort_engine (master|MERGING)
$

直接编辑文件

shell 复制代码
10321@coderzhao MINGW64 /e/Siemens_projects/code/comfort_engine (master|MERGING)
$ git status
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
        deleted by us:   bug.txt

no changes added to commit (use "git add" and/or "git commit -a")

编辑器直接处理冲突

shell 复制代码
10321@coderzhao MINGW64 /e/Siemens_projects/code/comfort_engine (master|MERGING)
$ git add .

10321@coderzhao MINGW64 /e/Siemens_projects/code/comfort_engine (master|MERGING)
$ git commit -am"hebingyixia"
[master 1365cd4] hebingyixia

处理之后提交

shell 复制代码
git push origin master 

其他用户拉取代码

shell 复制代码
git pull origin <other-branch>

拉取分支时候,自己分支的内容不会被覆盖。

相关推荐
purpleseashell_Lili8 小时前
commitizen,cz-git,husky 三者区别
git
摇滚侠8 小时前
零基础小白自学 Git_Github 教程,解决分支合并冲突,笔记14
笔记·git·github
我是李武涯11 小时前
如何修改git的commit消息
git
fruge11 小时前
Git 进阶技巧:分支管理、冲突解决、提交规范实操
大数据·git·elasticsearch
spencer_tseng12 小时前
Git-2.18.0-64-bit.exe client install
git
摇滚侠14 小时前
Idea Git 合并分支,rebase 和 merge 的区别,应该使用哪个,多人协作开发,禁止使用 rebase 合并分支
git·github
winfreedoms14 小时前
将 Git 恢复到「上一次提交(git commit)的版本」操作
git
系夏普14 小时前
Git 的三大工作区域:工作区、暂存区、本地仓库
git
Wang's Blog15 小时前
Elastic Stack梳理:索引与查询时的分词应用、配置优化与工程实践
大数据·elasticsearch·搜索引擎
Elasticsearch16 小时前
Elasticsearch:在隔离环境中安装 ELSER 模型
elasticsearch