合并时解决冲突后提交消息的问题
我是 Git 新手。目前,我正在经历这种情况:
步骤 0。我正在一个 sub 分支上工作
步骤 1。我已经添加了 &在我的 sub 分支上提交了 file1、file2、file3,分别提交消息 msg1、msg2、msg3。
步骤 2. 我 checkout master
以切换到 master 分支
步骤 3. 我 pull origin master
以使用最新的原始版本代码更新 master 分支
步骤 4我合并子分支
将我的工作代码合并到当前的主分支代码
然后,我在file2中遇到了冲突,
然后,我手动解决了冲突。现在,需要添加file2,因为该文件发生了更改。
步骤 5. 我在 master 分支中添加 file2,因为我已经解决了该文件的冲突
步骤 6. 我现在应该写什么提交消息?仅msg2?或者 msg1, msg2, msg3 现在都需要重写? (我不想丢失我工作的文件的提交消息 msg1,msg2,msg3)
I am new in Git. Currently, I am experiencing this scenario:
Step 0. I am working on a sub-branch
Step 1. I have added & commited file1, file2, file3 on my sub-branch with commit message msg1, msg2, msg3 respectively.
Step 2. I checkout master
to switch to master branch
Step 3. I pull origin master
to update master branch with latest origin version code
Step 4. I merge sub-branch
to merge my working code to the current master branch code
Then, I got conflict in file2,
Then, I manually resolved the conflicts. Now, file2 needs to be added because there is changes on this file.
Step 5. I add file2
in master branch, because I have resolved the conflicts on this file
Step 6. What commit message should I write now? the msg2 only? or msg1, msg2, msg3 all needs to be rewritten now? (I don't want to loose the commit messages msg1,msg2,msg3 for the files I worked)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不是为这些合并的提交编写新的提交消息;而是为这些合并的提交编写新的提交消息。您正在为合并提交本身编写提交消息。您的历史记录将如下所示:
您正在编写的提交消息是针对
X
的。提交1
、2
和3
是祖先,仍然在历史中,并且它们仍然有提交消息。没有办法通过合并来改变它们。如果没有冲突,
X
的提交消息将默认为Mergebranch 'sub-branch'
之类的内容。如果确实有冲突,它仍然会作为第一行,而且还会出现有冲突的文件列表:这是一个温和的暗示,表明您已经做了一些比简单合并更重要的事情 - 您必须做一些手动工作来解决
file2
中的冲突。如果您愿意,您可以添加有关导致这些冲突的原因以及如何解决这些冲突的快速说明。否则,请按原样使用该消息!请记住,这只是合并(和冲突解决)的描述。您合并的提交有自己的提交消息。You're not writing a new commit message for those merged commits; you're writing a commit message for the merge commit itself. Your history is going to look like this:
The commit message you're writing is for
X
. Commits1
,2
, and3
are ancestors, still in the history, and they still have their commit messages. There's no way to change those with a merge.The commit message for
X
, if you don't have conflicts, will default to something likeMerge branch 'sub-branch'
. If you do have conflicts, it'll still have that as the first line, but also a list of files which had conflicts:This is a gentle hint that you've done something more significant than just a simple merge - you had to do some manual work to resolve conflicts in
file2
. If you like, you can add a quick note about what caused those conflicts and how they were resolved. Otherwise, just use that message as-is! Remember, this is only a description of the merge (and conflict resolution). The commits you merged have their own commit messages.一旦解决了冲突,并且当您继续进行 git commit 时,
git add
应该会为合并和任何已解决的提交提供预构建的提交消息。不是吗?其他合并的提交不会丢失,您不必重写任何内容。git checkout master
git pull origin master
git merge BranchB
git add <冲突文件(2)>
git commit
第 7 步:如果在没有参数的情况下调用,应该打开默认的提交消息编辑器,其中包含一条不错的消息,解释合并和已解决的冲突(我相信)
Once you resolve the conflict and
git add <conflicted file>
when you go on togit commit
it should provide a prebuilt commit message for the merge and any resolved commits. Does it not? The other merged commits won't be lost, you shouldn't have to rewrite anything.git checkout master
git pull origin master
git merge BranchB
git add <conflicted file(2)>
git commit
Step 7: if called without params should open the default commit message editor with a decent message explaining the merge and resolved conflicts (I believe)