Git如何解决冲突
解决冲突
现在我把gitTest中的东西全删了包括那个.git文件。
初始化仓库git init,新建一个a.txt,在里边写个master,执行git add a.txt,然后执行git commit -m ‘add a.txt’
然后创建第一个分支 git branch feature1,然后创建第二个分支并切换到第二个分支git checkout -b feature2,在a.txt中另起一行添加feature2,然后执行git add a.txt和 git commit -m ‘feature2 add a word’,然后切换到master,git checkout master,把feature2分支合并到master分支, git merge –no-ff -m ‘merge feature2’ feature2。之后切换到feature1,git checkout feature1,在a.txt中另起一行添加feature1,然后执行git add a.txt和 git commit -m ‘feature1 add a word’。
现在整理一下,master分支a.txt中原始的数据为
master
- 1
后来创建了分支feature1里边的内容同样为
master
- 1
- 2
后来创建了feature2分支,并把feature2中的内容合并到了master,所以现在master中a.txt的内容为
master
feature2
- 1
- 2
- 3
后来我把feature1中的信息改为
master
feature1
- 1
- 2
- 3
现在master中的内容和feature1最初复制的内容不一样,现在切换到master分支,把feature1合并到master肯定会有冲突。
执行git merge feature1
$ git merge --no-ff -m 'merge feature1' feature1
Auto-merging a.txt
CONFLICT (content): Merge conflict in a.txt
Automatic merge failed; fix conflicts and then commit the result.
- 1
- 2
- 3
- 4
- 5
会发现有冲突了,这时候a.txt中的内容为
master
<<<<<<< HEAD
feature2
=======
feature1
>>>>>>> feature1
- 1
- 2
- 3
- 4
- 5
- 6
- 7
Git用<<<<<<<,=======,>>>>>>>标记出不同分支的内容。HEAD为当前所在分支的内容,也就是说现在master中的内容。feature1为feature1分支中的内容。
现在我a.txt中内容改为
master
feature2
feature1
- 1
- 2
- 3
- 4
然后执行
YZ@YZ MINGW64 /d/gitTest (master|MERGING)
$ git add a.txt
YZ@YZ MINGW64 /d/gitTest (master|MERGING)
$ git commit -m 'fix confict'
[master 6f57951] fix confict
YZ@YZ MINGW64 /d/gitTest (master)
$
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
这样就好了。git log –graph –pretty=oneline –abbrev-commit
–pretty=oneline这个参数的目的是不再显示Author和Date,只显示带有id号的一行。–abbrev-commit的意思是缩写id号。
YZ@YZ MINGW64 /d/gitTest (master)
$ git log --graph --pretty=oneline --abbrev-commit
* 7f2f3b5 (HEAD -> master) fix conflict
|\
| * f56a04d (feature1) feature1 add a word
* | 1387cb8 Merge branch 'feature2'
|\ \
| |/
|/|
| * 14ef937 (feature2) feature2 add a word
|/
* cf361f6 add a.txt
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
要修改上一条提交信息,可以使用git commit –amend命令。上一条的提交信息为fix config,但它其实是feature1分支的合并,解决合并时发生的冲突只是过程之一,这样标记是在不妥。于是,我们修改这条提交信息。
$ git commit -m 'merge feature1' --amend
[master dea2e9d] merge feature1
Date: Sun Aug 27 21:24:11 2017 +0800
- 1
- 2
- 3
- 4
再次查看日志,可以发现其变成了
$ git log --graph --pretty=oneline --abbrev-commit
* dea2e9d (HEAD -> master) merge feature1
|\
| * f56a04d (feature1) feature1 add a word
* | 1387cb8 Merge branch 'feature2'
|\ \
| |/
|/|
| * 14ef937 (feature2) feature2 add a word
|/
* cf361f6 add a.txt
Git如何解决冲突的更多相关文章
- git 提交解决冲突(转载)
转载 git 提交解决冲突 http://www.cnblogs.com/qinbb/p/5972308.html 一:git命令在提交代码前,没有pull拉最新的代码,因此再次提交出现了冲突. ...
- git如何解决冲突(代码托管在coding)
分支A提交合并请求到分支B,有冲突 git fetch code 拉取远程仓库的其他分支代码(我拉代码是remote add code所以这里是code,可以用git remote查看) git ch ...
- git之解决冲突
前面几次使用git,一直对于冲突的这个问题不是很理解,感觉有些时候就会产生冲突,在此记录一下解决冲突的流程 1.git bash上面冲突显示 2.在idea上面可以看到冲突的文件 3.去解决冲突 4. ...
- git 提交解决冲突
一:git命令在提交代码前,没有pull拉最新的代码,因此再次提交出现了冲突. error: You have not concluded your merge (MERGE_HEAD exists) ...
- git如何解决冲突(master分支的上的冲突--太岁头上动土)
欢迎加入前端交流群交流知识&&获取视频资料:749539640 git是什么就不废话了,详情点击 出现以下情况怎么解决? 有个index.ts文件 export const ENV = ...
- git pull解决冲突
git报错:Please commit your changes or stash them before you merge. 解决:1.不需要保留本地修改的话,直接将有冲突的文件还原再pull:g ...
- git学习(十一) idea git pull 解决冲突
测试如下: 先将远程的代码修改,之后更新: 之后将工作区修改的代码(这里修改的代码跟远程修改的位置一样)提交到本地,之后拉取远程的代码,会发现有冲突: Accept Yours 就是直接选取本地的代码 ...
- git -- 如何解决冲突
遇到冲突,首先要编辑冲突文件,可以使用vim或者其他工具,冲突文件变现为: <<<<HEAD 到 ==== :代表本地分支的修改内容 ==== 到 >>>&g ...
- Git 在解决冲突的时候文件覆盖
更新代码导致被还原或覆盖的场景:1.触发冲突的必要条件是修改同一个文件且修改的位置非常近,否则Git会自动合并其内容避免更新代码导致被还原或覆盖的解决方案1.少修改的地方(生产环境.公网测试环境):推 ...
随机推荐
- spoj Longest Common Substring
Longest Common Substring SPOJ - LCS 题意:求两个串的最长公共子串 /* 对一个串建立后缀自动机,用另一个串上去匹配 */ #include<iostream& ...
- P2105 K皇后
题意:$n*m$棋盘放置k个皇后,问几个格子不被攻击 1≤n,m≤20000,1≤k≤500 开set判重暴力$O(n*k)$然而,setMLE了QAQ 正解确实是$O(n*k)$的 以hang[i] ...
- 树链剖分【洛谷P1505】 [国家集训队]旅游
P1505 [国家集训队]旅游 题目描述 Ray 乐忠于旅游,这次他来到了T 城.T 城是一个水上城市,一共有 N 个景点,有些景点之间会用一座桥连接.为了方便游客到达每个景点但又为了节约成本,T 城 ...
- JS的类型转换
首先我们要知道,在 JS 中类型转换只有三种情况,分别是: 转换为布尔值 转换为数字 转换为字符串 我们先来看一个类型转换表格 转Boolean 在条件判断时,除了 undefined, null, ...
- Python导入命令 import from
一 module通常模块为一个文件,直接使用import来导入就好了.可以作为module的文件类型有".py".".pyo".".pyc" ...
- 使用css实现垂直居中
vartical-align vartical-align可以设置行内元素和表格单元格(table-cell)垂直对方式,所以如果元素是行内元素或者表格的话,可以直接应用这个属性对内容进行对齐设置.如 ...
- jquery each循环,实现break和continue的功能
break----用return false; continue --用return ture;
- HDU计算机学院大学生程序设计竞赛(2015’12)The Magic Tower
Problem Description Like most of the RPG (role play game), “The Magic Tower” is a game about how a w ...
- Codeforces 316C2 棋盘模型
Let's move from initial matrix to the bipartite graph. The matrix elements (i, j) for which i + j ar ...
- shell入门基础必备
作者:KornLee 2005-02-03 15:32:57 来自:Linux先生 1.建立和运行shell程序 什么是shell程序呢? 简单的说shell程序就是一个包含若干行 shel ...