kak*_*kyo 11 git version-control branching-and-merging
在将功能分支合并回主分支后,我通常需要默认执行合并提交.但我想在此提交中使用来自我的功能分支的原始提交消息,而不是"merge branch XXX".
我该怎么办?
Joe*_*Zim 15
只需将-m
参数传递给merge
命令:
$ git merge other-branch -m "Commit Message"
Run Code Online (Sandbox Code Playgroud)
Sim*_*ias 10
你基本上有两个选择.
简单的解决方案:不要合并,Rebase
Rebase你的分支在主分支之上,解决冲突,然后合并.由于您将拥有直接的历史记录,因此您将能够快进以进行合并,这将不会创建任何合并提交.
git checkout feature
git rebase main
# Resolve conflict if there is
git checkout main
git merge feature
Run Code Online (Sandbox Code Playgroud)
第二个选项:Rebase -i
您可以在合并后(在推送到遥控器之前)编辑历史记录.您可以使用rebase交互模式进行管理.
git checkout main
git merge feature
#You merge and resolve conflict
git rebase -i <sha of the commit before the merge>
Run Code Online (Sandbox Code Playgroud)
然后,您将被带入具有提交列表的交互式shell,例如:
pick 73c991e Create progress bar module
pick b8a0b83 merge branch feature
pick 2120f47 Add user form
pick 70c55e4 Quiz prototype system
Run Code Online (Sandbox Code Playgroud)
你只需要添加squash
或s
代替pick
:
pick 73c991e Create progress bar module
pick b8a0b83 merge branch feature
s 2120f47 Add user form
pick 70c55e4 Quiz prototype system
Run Code Online (Sandbox Code Playgroud)
此命令将共同壁球b8a0b83
和2120f47
.下一步将是一个提交文本编辑器,您可以将提交消息组合在一起,现在由您自己编辑它们以保留原始消息.
我发现在进行合并提交后。我可以添加修正提交“git ci --amend”来更改提交消息,这正是我所要求的。我会接受我自己的答案作为正确答案。
Simon Boudrias 和 Ranendra 给出了相关答案,但以不同的方式也同样有效。所以我对他们投了赞成票。
如果提交已经完成,您只需修改提交。
如果在提交之前,请git merge
在下面的示例中使用类似的内容:
$ git checkout mainBranch
$ git merge featureBranch --squash --no-commit
Run Code Online (Sandbox Code Playgroud)
您可能需要解决冲突。
这种方法避免了自动提交,所有文件都留在索引上;因此,您可以使用您想要的任何提交消息提交代码。
归档时间: |
|
查看次数: |
5029 次 |
最近记录: |