Git(10)-merge

Merge

  • 1. 無沖突合并
  • 2. 有沖突合并-手動解決
  • 3. git diff in merge
  • 4. 廢棄合并
  • 5. 合并策略

merge相關的操作的命令

git checkout master
git merge alternate
# 解決沖突 .....
git add file_1
git commit -m "Add slternate line 5, 6"
git reset --hard HEAD     # before merge commit將工作目錄和索引還原到git merge命令前狀態
git reset --hard ORIG_HEAD # after merge commit 將工作目錄和索引還原到git merge命令前狀態
git checkout -m            # 把沖突解決方案搞砸了,想要返回到沖突的原始狀態

合并操作:檢出目標分支->確保工作區干凈->執行合并操作。執行合并操作后,另一個分支不受影響。

1. 無沖突合并

合并不涉及相同文件的相同部分

chenyingying01@cyy merge % git checkout master
Switched to branch 'master'
chenyingying01@cyy merge % git status
On branch master
nothing to commit, working tree clean
chenyingying01@cyy merge % git merge alternate
Merge made by the 'recursive' strategy.file | 1 +1 file changed, 1 insertion(+)
chenyingying01@cyy merge % git log --graph --pretty=oneline --abbrev-commit
*   50fc402 (HEAD -> master) Merge branch 'alternate'
|\
| * 4fb8628 (alternate) Add alternate's line 4
* | 608c235 Another file
|/
* 61570a2 Initial 3 line file
chenyingying01@cyy merge %

2. 有沖突合并-手動解決

合并涉及相同文件的相同部分, merge時會產生沖突。需要手動的去修改沖突,然后在add, commmit。 代碼分支合并時必須保證合入后不會影響原有的功能。

chenyingying01@cyy merge % git branchalternate
* master
chenyingying01@cyy merge % cat >> file
Line 5 stuff
Line 6 stuff
chenyingying01@cyy merge % git add file
chenyingying01@cyy merge % git commit -m "Add line 5 and line 6"
[master f0adb70] Add line 5 and line 61 file changed, 2 insertions(+)chenyingying01@cyy merge % git checkout alternate
Switched to branch 'alternate'
chenyingying01@cyy merge % cat >> file
Line 5 alternate stuff
Line 6 alternate stuff
chenyingying01@cyy merge % git diff
diff --git a/file b/file
index 3754bb3..260d21c 100644
--- a/file
+++ b/file
@@ -2,3 +2,5 @@ line 1 stuffline 2 stuffline 3 stuffline 4 alternate stuff
+Line 5 alternate stuff
+Line 6 alternate stuff
chenyingying01@cyy merge % git add file
chenyingying01@cyy merge % git commit -m "Add slternate line 5, 6"
line 1 stuff
[alternate 8de3d40] Add slternate line 5, 61 file changed, 2 insertions(+)chenyingying01@cyy merge % git checkout master
Switched to branch 'master'
chenyingying01@cyy merge % git merge alternate
Auto-merging file
CONFLICT (content): Merge conflict in file
Automatic merge failed; fix conflicts and then commit the result.
chenyingying01@cyy merge % git diff
diff --cc file
index f1209a9,260d21c..0000000
--- a/file
+++ b/file
@@@ -2,5 -2,5 +2,10 @@@ line 1 stufline 2 stuffline 3 stuffline 4 alternate stuff
++<<<<<<< HEAD+Line 5 stuff+Line 6 stuff
++=======
+ Line 5 alternate stuff
+ Line 6 alternate stuff
++>>>>>>> alternate
chenyingying01@cyy merge % vim file              # 手動解決沖突
chenyingying01@cyy merge % git add file
chenyingying01@cyy merge % git commit
[master b80e372] Create commit 7015896: Merge branch "alternate"
chenyingying01@cyy merge % git log --graph --pretty=oneline --abbrev-commit
*   b80e372 (HEAD -> master) Create commit 7015896: Merge branch "alternate"
|\
| * 8de3d40 (alternate) Add slternate line 5, 6
* | f0adb70 Add line 5 and line 6
* | 50fc402 Merge branch 'alternate'
|\|
| * 4fb8628 Add alternate's line 4
* | 608c235 Another file
|/
* 61570a2 Initial 3 line file
chenyingying01@cyy merge %

3. git diff in merge

在編程的過程中,提倡使用幾個單獨概念的,定義良好的提交進行merge,而不是等到最后一個大的龐大提交時再merge.
針對有沖突文件,git diff 命令的輸出是 git diff HEAD 和git diff MERGE_HEAD 命令的結果的組合。

chenyingying01@cyy conflict % git diff
diff --cc hello
index e63164d,562080a..0000000
--- a/hello
+++ b/hello
@@@ -1,3 -1,3 +1,7 @@@hello
++<<<<<<< HEAD+worlds
++=======
+ world
++>>>>>>> altYay!
chenyingying01@cyy conflict % git diff HEAD
diff --git a/hello b/hello
index e63164d..1f2f61c 100644
--- a/hello
+++ b/hello
@@ -1,3 +1,7 @@hello
+<<<<<<< HEADworlds
+=======
+world
+>>>>>>> altYay!
chenyingying01@cyy conflict % git diff MERGE_HEAD
diff --git a/hello b/hello
index 562080a..1f2f61c 100644
--- a/hello
+++ b/hello
@@ -1,3 +1,7 @@hello
+<<<<<<< HEAD
+worlds
+=======world
+>>>>>>> altYay!

4. 廢棄合并

# 1.before merge commit 將工作目錄和索引還原到git merge命令前狀態
git reset --hard HEAD
# 2.after merge commit 將工作目錄和索引還原到git merge命令前狀態
# ORIG_HEAD git 把原始分支的HEAD放在ORIG_HEAD中
git reset --hard ORIG_HEAD  
# 3.把沖突解決方案搞砸了,想要返回到沖突的原始狀態
git checkout -m

5. 合并策略

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/444660.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/444660.shtml
英文地址,請注明出處:http://en.pswp.cn/news/444660.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

elasticsearch的Linux下安裝報錯問題解決

1.啟動報錯如下: vim /etc/security/limits.conf 然后修改如下 * soft nofile 65536 * hard nofile 65536sudo vi /etc/pam.d/common-session 添加 session required pam_limits.so sudo vi /etc/pam.d/common-session-noninteractive 添加 session required pam_limits.so…

leetcode120. 三角形最小路徑和

給定一個三角形&#xff0c;找出自頂向下的最小路徑和。每一步只能移動到下一行中相鄰的結點上。 例如&#xff0c;給定三角形&#xff1a; [ [2], [3,4], [6,5,7], [4,1,8,3] ] 自頂向下的最小路徑和為 11&#xff08;即&#xff0c;2 3 5 1 11&#xff0…

Elasticsearchan相關插件和工具安裝

1、下載elasticsearch-head的源碼包 地址&#xff1a;https://github.com/mobz/elasticsearch-head/releases 2、安裝node運行環境 地址&#xff1a;https://nodejs.org/en/download/ 3、安裝完node之后編譯elasticsearch-head 執行npm install -g grunt-cli編譯源碼 執行…

Git(11)-cherry-pick、reset、rebase

更改提交&#xff0c;版本回退1.get reset 重置HEAD指針的指向2.git cherry-pick3.git revert4.git commit --amend修改提交5.git rebase 變基提交5.1 git rebase --onto5.2rebase 產生沖突&#xff0c;解決沖突/終止變基5.3git rebase -i6. rebase Vs mergegit 提供了【修改】…

Elasticsearch集群節點配置詳解

注意&#xff1a;如果是在局域網中運行elasticsearch集群也是很簡單的&#xff0c;只要cluster.name設置一致&#xff0c;并且機器在同一網段下&#xff0c;啟動的es會自動發現對方&#xff0c;組成集群。 三、配置淺涉 elasticsearch的config文件夾里面有兩個配置文件&#…

MongoDB修改器使用

歡迎關注我的新微信公眾號 ipgame,有什么問題可以提供交流的平臺,歡迎大家討論。 對于文檔的更新除替換外,針對某個或多個文檔只需要部分更新可使用原子的更新修改器,能夠高效的進行文檔更新。更新修改器是中特殊的鍵, 用來指定復雜的操作,比如增加、刪除或者調整鍵,還…

Git(12)-stash, reflog

git stash1. git stash2. reflog命令概覽git stash save "WIP:xxxxx" # save后可以跟筆記&#xff0c;WIP:work in process git stash list # 查看存儲狀態棧的條目 git stash pop # 當前工作目錄和索引還原至最近一次save操作的內容…

cmake生成Win64位工程

使用cmake編譯64的dll 一開始使用cmake --build .來生成了dll&#xff0c;在導入到java項目中使用的時候&#xff0c;才發現是32位的。導致程序不能正常運行&#xff0c;報錯如下&#xff1a; Exception in thread "main" java.lang.UnsatisfiedLinkError Cant load…

leetcode 106. 從中序與后序遍歷序列構造二叉樹

根據一棵樹的中序遍歷與后序遍歷構造二叉樹。 注意: 你可以假設樹中沒有重復的元素。 例如&#xff0c;給出 中序遍歷 inorder [9,3,15,20,7] 后序遍歷 postorder [9,15,7,20,3] 返回如下的二叉樹&#xff1a; 3 / \ 9 20 / \ 15 7 思路&#xff1a;和前…

Mat矩陣(圖像容器)的創建及CV_8UC1,CV_8UC2等參數詳解

一&#xff09;Mat矩陣(圖像容器)創建時CV_8UC1,CV_8UC2等參數詳解 1--Mat不但是一個非常有用的圖像容器類,同時也是一個通用的矩陣類 2--創建一個Mat對象的方法很多 3--使用Mat圖像容器類創建Mat類的對象 //! default constructor Mat(); //! constructs …

TensorFlow(1)-模型相關基礎概念

TensorFlow-11.Graph對象2.Session對象3.Variabels變量4. placeholders與feed_dict5. tf.train.Saver() 模型參數保存、加載Tensorflow 中文官網教程–2.0版本的官方教程 TensorFlow教程&#xff1a;TensorFlow快速入門教程&#xff08;非常詳細&#xff09; pytorch Vs tensor…

memcache的使用入門C++代碼

下載源碼編譯&#xff0c;memcached就是生成的主程序&#xff0c;啟動可指定端口&#xff0c;memcached作為server端&#xff0c;依然是我們熟悉的cs模式&#xff0c;使用兩個client一個setkey&#xff0c;一個getkey一百萬個做測試。 ./memcached -d -m 300 -p 11211 -u root…

leetcode78 子集

給定一組不含重復元素的整數數組 nums&#xff0c;返回該數組所有可能的子集&#xff08;冪集&#xff09;。 說明&#xff1a;解集不能包含重復的子集。 示例: 輸入: nums [1,2,3] 輸出: [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ] 思路&…

Fiddler抓包工具使用

先下載Fiddler 歡迎關注我的新微信公眾號 ipgame&#xff0c;有什么問題可以提供交流的平臺&#xff0c;歡迎大家討論。 電腦最好是筆記本&#xff0c;這樣能和手機保持統一局域網內&#xff1b;其他不多說&#xff0c;直接說步驟了。 一.對PC&#xff08;筆記本&#xff0…

Tensorboard--模型可視化工具

Tensorboard1.tensorboard in tensorflow1.1 tensorboard的啟動過程1.2 tf.summary 可視化類型1.3 tf.summary 使用demo2.tensorboard in pytorch2.1 SummaryWriter 使用demo12.2 tSummaryWriter 使用demo22.3 tensorboard 數據再讀取tensorboard in tensorflow &#xff1a;te…

opencv findContours 報錯_acrt_first_block == header

報錯_acrt_first_block header 之前一直使用OpenCV3.3VS2015 void AOIAlgorithm::findUnits(Mat& blkGray, vector<vector<cv::Point>> & blkContours) {Mat blkOBW;blur(blkGray, blkGray, cv::Size(5, 5));threshold(blkGray, blkOBW, 0, 255, CV_THR…

TensorFlow(2)-訓練數據載入

tensorflow 訓練數據載入1. tf.data.Dataset2. dataset 創建數據集的方式2.1 tf.data.Dataset.from_tensor_slices()2.2 tf.data.TextLineDataset()2.3 tf.data.FixedLengthRecordDataset()2.4 tf.data.TFRecordDataset()3. dateset 迭代操作iterator3.1 make_one_shot_iterato…

leetcode66. 加一

給定一個由整數組成的非空數組所表示的非負整數&#xff0c;在該數的基礎上加一。 最高位數字存放在數組的首位&#xff0c; 數組中每個元素只存儲單個數字。 你可以假設除了整數 0 之外&#xff0c;這個整數不會以零開頭。 示例 1: 輸入: [1,2,3] 輸出: [1,2,4] 解釋: 輸入…

設備硬件加密方法

在機器視覺或者一些傳統制造業行業里經常牽扯到軟件加密算法,或者一些簡單的加密,比如相機綁定,或者USB接口綁定之類的,那么針對這些硬件設備綁定加密方式,我這里簡單的提供一個方法來實現: 方法很簡單,從設備管理器里查找關心的USB設備,對比PID,VID和全球唯一標識GU…

addr2line 和 tombstone問題分析

做安卓開發的同學對于tombstone問題應該是很熟悉了,但是對于如何排查和分析值得總結和整理的,這篇文章對入門安卓開發的技術來說是個入門指導,同時對安卓開發的中高級開發也有借鑒。 首先我們來說下什么是tombstone : 當一個動態庫(native 程序)開始執行時,系統會注冊…