Git的多人协作和分支处理测试

首先配置ssh密钥

克隆项目

  • 配置两台主机(一台本地mac,一台云服务器)通过这样的方式模拟多人开发。

创建分支

[root@ ~/Git_test_多人协作和冲突合并/branch_test]$ ls
README.md
[root@ ~/Git_test_多人协作和冲突合并/branch_test]$ git branch
* master
[root@ ~/Git_test_多人协作和冲突合并/branch_test]$ git branch yun
[root@ ~/Git_test_多人协作和冲突合并/branch_test]$ git branch
* masteryun
[root@ ~/Git_test_多人协作和冲突合并/branch_test]$ 

转移到分支并在分支添加项目

[root@ ~/branch_test]$ ls
README.md
[root@ ~/branch_test]$ git checkout yun
切换到分支 'yun'
[root@ ~/branch_test]$ git branchmaster
* yun
[root@ ~/branch_test]$ ls
README.md
[root@ ~/branch_test]$ touch yun1.c
[root@ ~/branch_test]$ ls
README.md  yun1.c
[root@ ~/branch_test]$ git add yun1.c
[root@ ~/branch_test]$ git commit -m "yun1.c"*** Please tell me who you are.Rungit config --global user.email "you@example.com"git config --global user.name "Your Name"to set your account's default identity.
Omit --global to set the identity only in this repository.fatal: empty ident name  not allowed

要提交自己的用户名和邮箱才可以继续

  • 提交完毕后
[root@ ~/branch_test]$ git commit -m "yun1.c"                   
[yun eb267c4] yun1.c1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 yun1.c

冲突测试

master

  • 首先使用yun提交一段代码
[root@ ~/branch_test]$ git branch 
* masteroriginyun
[root@ ~/branch_test]$ ls
README.md  yun1.c
[root@ ~/branch_test]$ cat yun1.c 
hello world
[root@ ~/branch_test]$ git push origin master
Total 0 (delta 0), reused 0 (delta 0)
To git@git.github.com:kouhaozhe/branch_test.giteb267c4..025a01e  master -> master
  • 这是master的yun1.c文件就有了一段代码
yun1.c 12 Bytes
hello world
  • 我们使用mac进行提交
khz:branch_test kouhz$ ls
README.md	yun1.c
khz:branch_test kouhz$ vim yun1.c 
khz:branch_test kouhz$ cat yun1.c 
HELLO WORLDkhz:branch_test kouhz$ git add yun1.c 
khz:branch_test kouhz$ git commit -m "HELLO WORLD"
[master 75da4f2] HELLO WORLD1 file changed, 1 insertion(+)
khz:branch_test kouhz$ git push
To git.github.com:kouhaozhe/branch_test.git! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@git.github.com:kouhaozhe/branch_test.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
khz:branch_test kouhz$ 

冲突时我们要先git pull再git push

  • git pull
  • git diff 查看文件的不同
<<<<<<< HEAD
HELLO WORLD
=======
hello world
>>>>>>> 8d4d57c701bfbda71cc442caf2017c01437a80d1

其他分支

yun 分支添加文字并提交

[root@ ~/branch_test]$ git branchmaster
* yun
[root@ ~/branch_test]$ ls
README.md  yun1.c
[root@ ~/branch_test]$ vim yun1.c 
[root@ ~/branch_test]$ cat yun1.c 
yun hello[root@ ~/branch_test]$ git add yun1.c
[root@ ~/branch_test]$ git commit -m "yun yun1.c"
[yun 4d7c92c] yun yun1.c1 file changed, 1 insertion(+), 1 deletion(-)
[root@ ~/branch_test]$ git push
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 278 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: 
remote: To create a merge request for yun, visit:
remote:   http://git.github.com/kouhaozhe/branch_test/merge_requests/new?merge_request%5Bsource_branch%5D=yun
remote: 
To git@git.github.com:kouhaozhe/branch_test.git025a01e..4d7c92c  yun -> yun
[root@ ~/Git_test_多人协作和冲突合并/branch_test]$ 
  • 这时网页已经有了我们提交的带着,我们切换到另一台机器
    另一台电脑除了自己创建的分支,看不见另一台电脑创建的分支,这时使用命令
khz:branch_test kouhz$ git branchmac
* master

同步之后没有yun这个分支,操作命令
切换另一台主机创建的分支

git checkout -b yun origin/yun 

Tips:
error: you need to resolve your current index first

khz:branch_test kouhz$ git reset --merge
khz:branch_test kouhz$ git checkout -b yun origin/yun
Branch ‘yun’ set up to track remote branch ‘yun’ from ‘origin’.
Switched to a new branch ‘yun’

在进行添加代码

khz:branch_test kouhz$ cat yun1.c 
<<<<<<< HEAD
hello world
HELLO WORLD
=======
yun hello
>>>>>>> 4d7c92c5686128aa3c99c25f3dbfdbbd88f8cf5e
khz:branch_test kouhz$ vim yun1.c 
khz:branch_test kouhz$ cat yun1.c 
yun hello
hello world
HELLO WORLDkhz:branch_test kouhz$ git add yun1.c 
khz:branch_test kouhz$ git commit -m "mac"
[yun ae006aa] mac
khz:branch_test kouhz$ git push origin yun
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 577 bytes | 577.00 KiB/s, done.
Total 6 (delta 0), reused 0 (delta 0)
remote: 
remote: To create a merge request for yun, visit:
remote:   http://git.github.com/kouhaozhe/branch_test/merge_requests/new?merge_request%5Bsource_branch%5D=yun
remote: 
To git.github.com:kouhaozhe/branch_test.git4d7c92c..ae006aa  yun -> yun

切换到另一台主机

  • 进行git pull操作,结果失败了!原因是没有指定本地dev分支与远程origin/dev分支的链接
[root@ ~/branch_test]$ git pull
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
来自 git.github.com:kouhaozhe/branch_test4d7c92c..ae006aa  yun        -> origin/yun
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for detailsgit pull <remote> <branch>If you wish to set tracking information for this branch you can do so with:git branch --set-upstream-to=origin/<branch> yun
  • 我们按照提示进行操作
    git branch --set-upstream-to=origin/ yun
    git branch --set-upstream-to=origin/yun yun

这时操作就成功了

[root@ ~/branch_test]$ cat yun1.c 
yun hello
[root@ ~/branch_test]$ git pull
更新 4d7c92c..ae006aa
Fast-forwardyun1.c | 2 ++1 file changed, 2 insertions(+)
[root@ ~/Git_test_多人协作和冲突合并/bra
nch_test]$ cat yun1.c 
yun hello
hello world
HELLO WORLD

如何一次性永久保存密码

git config --global credential.helper store

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/382454.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python 碎片整理 threading模块小计

threading模块中&#xff0c; start()与run()方法的区别 threading.start() 方法是开启一个线程 threading.run() 方法则是普通的函数调用

git教程目录

git入门教程 PyCharm和git安装教程 Git的多人协作和分支处理测试

msyql 禁止远程访问

1. use mysql 2. select host , user from user; 查看用户 与 对应的host 3. 将 host 中是 %的改为 localhost&#xff0c; 酌情也可以其他用户 的host限制为localhost update user set host "localhost" where user "root" and host "%" 4. …

mysql索引回表

先索引扫描&#xff0c;再通过ID去取索引中未能提供的数据&#xff0c;即为回表。 建表 mysql> create table T( id int primary key, k int not null, name varchar(16), index (k))engineInnoDB;如果语句是 select * from T where ID500&#xff0c;即主键查询方式&am…

C++ 执行cmd命令 并获取输出

这是参考别人的 &#xff0c;具体来源忘了&#xff0c;唉&#xff0c;等想起来一定补上出处 头文件 PipeCmd.h #ifndef _PIPE_CMD_H_ #define _PIPE_CMD_H_#include <Windows.h>// 执行 cmd 命令, 并获取执行结果数据 BOOL PipeCmd(char *pszCmd, char *pszResultBuffe…

iterm2 保存阿里云登陆并防止断开连接

commando edit profiles新增一个页面 添加命令 ssh -A -p 22 -o ServerAliveInterval60 rootIP

QString中包含中文的时候, 转为char *

转载自 https://blog.csdn.net/mihang2/article/details/39026865 QString中包含中文的时候&#xff0c; 转为char * void FileEncWidget::QString2ANSI(QString text, char **pOut) {std::wstring wIn text.toStdWString();char *pcstr (char *)malloc(sizeof(char)*(2 * w…

brew安装

官网&#xff1a;http://brew.sh/ 安装软件&#xff1a;brew install 软件名&#xff0c;例&#xff1a;brew install wget搜索软件&#xff1a;brew search 软件名&#xff0c;例&#xff1a;brew search wget卸载软件&#xff1a;brew uninstall 软件名&#xff0c;例&#…

关于异步IO模型的学习

看到两篇不错的文章&#xff0c;转载了&#xff1a; https://www.cnblogs.com/fanzhidongyzby/p/4098546.html https://www.cnblogs.com/aspirant/p/9166944.html

centos 无法连接网络

最小化安装&#xff0c;没有ifconfig默认没法联网 cd /etc/sysconfig/network-scripts/ sudo vi ifcfg-en33 也有可能是其他后缀 找到ONBOOTno service network restart 然后yum install net-tools

C++实现utf8和gbk编码字符串互相转换

不同系统或者服务器之间消息传递经常遇到编码转换问题&#xff0c;这里用C实现了一个轻量的gbk和utf8互相转换&#xff0c;可跨平台使用。&#xff08;重量级的可以用libiconv库&#xff09; 在windows下用<windows.h>头文件里的函数进行多字节和宽字符转换&#xff0c;…

mysql5.7初始密码查看及密码重置

查看初始密码 grep temporary password /var/log/mysqld.logcat /root/.mysql_secret mysql密码找回 密码重置 vi /etc/my.cnf 在[mysqld]下加上 skip-grant-tables&#xff0c;如&#xff1a; [mysqld] datadir/var/lib/mysql socket/var/lib/mysql/mysql.sock skip-g…

Ubuntu Linux系统环境变量配置文件

Ubuntu Linux系统环境变量配置文件&#xff1a; /etc/profile : 在登录时,操作系统定制用户环境时使用的第一个文件 ,此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行。 /etc /environment : 在登录时操作系统使用的第二个文件, 系统在读取你自己的profi…

Mooc的Python3学习笔记

文章目录一些优秀的博主仅供自己查阅&#xff01;&#xff01;&#xff01;首先是掌握基本语法&#xff01;内置的运算符函数函数模块补充知识点pass函数返回多个值关于默认参数使用的注意事项可变参数的使用方法天天向上代码单元测试异常处理代码单例模式Python 中的 if __nam…

使用supervisord 来守护 nginx进程

supervisord 简介&#xff1a; Supervisord 是用 Python 实现的一款的进程管理工具&#xff0c;supervisord 要求管理的程序是非 daemon 程序&#xff0c;supervisord 会帮你把它转成 daemon 程序&#xff0c;因此如果用 supervisord 来管理进程&#xff0c;进程需要以非daemo…

Mac快捷键和实用技巧

文章目录如何更改应用图标怎么移动Mac状态栏的图标macOS常用快捷键多开QQ如何更改应用图标 https://www.macdu.org/16592.html 怎么移动Mac状态栏的图标 https://www.macdu.org/16683.html macOS常用快捷键 https://www.macdu.org/16607.html 多开QQ https://www.macdu.…

vs2017编译QT with ssl

背景&#xff1a;项目中使用的Qt环境不支持https请求&#xff0c;原因是 源码编译的时候没有链接相应的ssl库文件。需要重新编译qt 第一步 先编译Openssl 1)安装perl&#xff0c;并配置环境变量 下载地址&#xff1a; http://downloads.activestate.com/ActivePerl/releases/5…

go语言实现2048小游戏(完整代码)

文章目录2048逻辑分析完整代码2048逻辑分析 2048小游戏的基本操作是上下左右&#xff0c;每个操作的逻辑都不太一样&#xff01;这个时候&#xff0c;通过数组旋转的方式。将所有操作转换为向上的操作 git地址 https://gitee.com/hodgekou/golang.git package mainimport (&q…

动态二维码免费制作

python3制作二维码 很多网站都可以自定义制作很漂亮的二维码&#xff0c;提供了各种素材&#xff0c;但是输出文件又各种限制&#xff0c;非要买她的会员不可。好吧&#xff01;那我们就自己做一个。&#xff08;大牛的开源项目&#xff09; 最终效果 开源项目网站 git clon…

vs 2017 静态库 动态库 的初步使用

静态库的初步使用 新建 静态库 项目 Lib1 会产生 sln文件与vcproj文件&#xff0c;vcproj是工程文件&#xff0c;sln是解决方案文件 一个解决方案可以有多个工程 在头文件(Lib1.h)写函数声明&#xff0c;在cpp文件定义函数实现 这时候右键点击项目 ->生成, 会产生 Lib1.lib…