我正在分支工作b1
。可以说要部署的主要分支stage
。我b1
从master
这里分支了-这是我们的惯例。
情况就是这样。我目前在b1
。在一个文件中,我称它为users.txt
一个片段,如下所示:
print("Hello user")
print("Bye user")
在stage
分支中,相同的代码段如下所示:
print("Hello user")
print("You are welcome")
print("Bye user")
现在,在我的工作(b1
)分支中,我想进行这样的更改,使之合并时stage
将删除此行:print("You are welcome")
并使该stage
分支看起来像它。换句话说,执行后git checkout stage
git merge b1
-stage
文件user.txt
如下所示:
print("Hello user")
print("Bye user")
换句话说:删除stage
branchb1
中的行,方法是在分支中进行更改,其中要删除的行b1
最初不存在。
有一点需要注意:我不能合并stage
成b1
按照惯例(说实话-我不明白)
(过时答案的免责声明:问题是在我的答案之后进行编辑的,现在stage
不应该合并到功能分支中)
由于b1
且文件的stage
初始状态不同users.txt
,因此您首先必须进行更新b1
以赶上最近的更改,即文件缺少的新行。
git checkout stage
git pull
git checkout b1
git merge stage
在这一点上,您可能(或不需要)解决冲突。然后,您users.txt
将类似于上一个stage
。只需删除该行,添加并提交:
# go delete the line in "users.txt" then...
git add path/to/users.txt
git commit -m "Deleted said line"
关于没有合并功能的评论后进行编辑
如果您不能合并stage
,但被允许合并线的来源要素,请继续。您必须找到它来自哪个提交:
git log -1 --oneline -S "Copy the text of the line here"
这将输出接触该行的最后一次提交。注意其哈希值。然后,可以按照Theraot在注释中的提示,以樱桃选择的方式将提交提交导入分支。
git cherry-pick <commitHash>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句