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.pswp.cn/news/382454.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/382454.shtml
英文地址,請注明出處:http://en.pswp.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…