【发布时间】:2013-12-03 06:00:06
【问题描述】:
我正在使用 git 来跟踪我的一个小型网站的开发。我目前有两个分支:
-
master分支,其代码(据说)已准备好部署 -
dev分支,我会在其中尝试直到我认为它们已准备好部署
为了养成良好的习惯,以便将开发升级到更多人,我通常将master 分支与dev 分支合并,然后检查master 分支并将dev 合并到其中– 以便能够解决 dev 分支而不是 master 中的任何冲突。
上次我这样做时,一些代码就消失了(id="all_text" 的 css 代码,请参阅下面的代码)。我认为这是因为 master 分支中没有代码,并且因为我将 master 代码移动到 dev 分支中(但这不是我记得它的行为方式),所以我取消了合并( git reset --merge;我在 git 1.7.0.3),检查了 master 分支并将其与 dev 分支合并。结果相同——#all_text css 中的大部分代码都消失了。
我不知道为什么会这样。最新的更改在 dev 分支上,因此它们应该合理地在合并中进行,而不是被删除。
有没有什么办法可以解决这个问题,而无需手动将dev 中的文档内容复制到master?
开发内容(index.css)
body {
margin:0;
padding:0;
}
/* attributes for the <div> that encapsules the h1 and the encouragement */
#all_text {
position: relative;
height: 50%;
width: 70%;
margin-top:8em;
margin-left:auto;
margin-right:auto;
text-align: center;
// background-color: yellow; // Trace code to better see the design
}
h1 {
position: relative;
text-align: center;
font-size: 700%;
color: #4970A8;
/* color: #5AA0FF; */
text-shadow: 4px 4px 8px gray;
// background-color: green; // Trace code to better see the design
}
div.encouragement {
position: relative;
width: 70%;
bottom: 25px;
color: #4970A8;
font-size: 170%;
// background-color: red; // Trace code to better see the design
}
主内容(index.css)
#all_text {
position: relative;
}
h1 {
color: #4970A8;
/* color: #5AA0FF; */
text-align: center;
/* text-vertica-align: center; */
font-size: 700%;
position: relative;
top:30%;
text-shadow: 4px 4px 8px gray;
}
div.encouragement {
color: #4970A8;
text-align: center;
font-size: 150%;
/* position: absolute;
top: 5%m;
left:7%em; */
/* text-shadow: 2px 2px 8px gray; */
}
合并的内容 (index.css)
#all_text {
position: relative;
}
h1 {
<<<<<<< HEAD
position: relative;
text-align: center;
font-size: 700%;
color: #4970A8;
/* color: #5AA0FF; */
text-shadow: 4px 4px 8px gray;
// background-color: green; // Trace code to better see the design
}
div.encouragement {
position: relative;
width: 70%;
bottom: 25px;
color: #4970A8;
font-size: 170%;
// background-color: red; // Trace code to better see the design
=======
color: #4970A8;
/* color: #5AA0FF; */
text-align: center;
/* text-vertica-align: center; */
font-size: 700%;
position: relative;
top:30%;
text-shadow: 4px 4px 8px gray;
}
div.encouragement {
color: #4970A8;
text-align: center;
font-size: 150%;
/* position: absolute;
top: 5%m;
left:7%em; */
/* text-shadow: 2px 2px 8px gray; */
>>>>>>> master
}
#all_text{…} 部分中的大部分文本发生了什么变化?
先谢谢了。
更新:添加了merge-base(根据dyng’s指令)。
运行git show $(git merge-base dev master) 给了我这个:
diff --git a/www/index.css b/www/index.css
index b837a87..d8c48ef 100644
--- a/www/index.css
+++ b/www/index.css
@@ -1,25 +1,44 @@
+body {
+ margin:0;
+ padding:0;
+}
+
+/* attributes for the <div> that encapsules the h1 and the encouragement */
#all_text {
position: relative;
+ height: 50%;
+ width: 70%;
+ margin-top:8em;
+ margin-left:auto;
+ margin-right:auto;
+ text-align: center;
+
+// background-color: yellow; // Trace code to better see the design
}
+
h1 {
color: #4970A8;
/* color: #5AA0FF; */
text-align: center;
-/* text-vertica-align: center; */
+ display: inline-block;
font-size: 700%;
position: relative;
- top:30%;
+ left:0.5em;
+
text-shadow: 4px 4px 8px gray;
+
+// background-color: green; // Trace code to better see the design
}
-div.encouragement {
+span.encouragement {
color: #4970A8;
- text-align: center;
- font-size: 150%;
-/* position: absolute;
- top: 5%m;
- left:7%em; */
-/* text-shadow: 2px 2px 8px gray; */
+ font-size: 170%;
+ position: relative;
+ top: 3em;
+ right:18em;
+
+
+// background-color: red; // Trace code to better see the design
}
\ No newline at end of file
【问题讨论】:
-
git merge-base dev master将在合并dev和master时告诉合并基础(这是一个提交),index.css在那个提交中看起来像什么? (这里是一行命令:git show $(git merge-base dev master):/path/to/index.css) -
感谢您提供有关如何操作的明确说明,请参阅上面的更新以获取结果。 (我在没有路径规范的情况下运行它,因为当我包含路径时它给出了一个致命错误,但我在上面的更新中遗漏了其他文件。)我在 dev 分支中运行它。据我了解,+'es 告诉我与 master 分支相比,在 dev 分支中添加了哪些行(以及 -'es 已删除的内容),但我不太确定如何处理该信息– 我已经知道我想保留什么,但 git 不知道 ;) ).
-
@dyng 也许我对 VonC 的评论也有帮助(事实上我更新了服务器端的东西并在 dev 分支上进行单独开发时将其获取到 master)。但这并不能解释为什么 git 会丢弃我在 dev 分支中添加的主体选择器(例如)。
-
合并基础信息意味着在 master 分支中,添加了“all_text”中的行然后删除。虽然 dev 与 merge-base 保持一致,但在 master 中这些行已被删除。在合并期间,如果一个分支与合并基础不同而另一个保持不变,Git 将始终接受更改的分支作为合并结果。
标签: git merge merge-conflict-resolution