合并时解决冲突后提交消息的问题

发布于 2024-10-25 19:59:36 字数 696 浏览 3 评论 0原文

我是 Git 新手。目前,我正在经历这种情况:

步骤 0。我正在一个 sub 分支上工作

步骤 1。我已经添加了 &在我的 sub 分支上提交了 file1、file2、file3,分别提交消息 msg1、msg2、msg3

步骤 2. 我 checkout master 以切换到 ma​​ster 分支

步骤 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水溶 2024-11-01 19:59:36

您不是为这些合并的提交编写新的提交消息;而是为这些合并的提交编写新的提交消息。您正在为合并提交本身编写提交消息。您的历史记录将如下所示:

- x - o - o - o (origin/master) - X (master)
   \                             /
    1 - 2 - 3 (sub-branch) ------

您正在编写的提交消息是针对 X 的。提交 123 是祖先,仍然在历史中,并且它们仍然有提交消息。没有办法通过合并来改变它们。

如果没有冲突,X 的提交消息将默认为 Mergebranch 'sub-branch' 之类的内容。如果确实有冲突,它仍然会作为第一行,而且还会出现有冲突的文件列表:

 Merge branch 'sub-branch'

 Conflicts:
     file2

这是一个温和的暗示,表明您已经做了一些比简单合并更重要的事情 - 您必须做一些手动工作来解决 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:

- x - o - o - o (origin/master) - X (master)
   \                             /
    1 - 2 - 3 (sub-branch) ------

The commit message you're writing is for X. Commits 1, 2, and 3 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 like Merge 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:

 Merge branch 'sub-branch'

 Conflicts:
     file2

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.

北凤男飞 2024-11-01 19:59:36

一旦解决了冲突,并且当您继续进行 git commit 时,git add 应该会为合并和任何已解决的提交提供预构建的提交消息。不是吗?其他合并的提交不会丢失,您不必重写任何内容。

  1. 提交到 BranchB
  2. git checkout master
  3. git pull origin master
  4. git merge BranchB
  5. 解决文件中的冲突
  6. git add <冲突文件(2)>
  7. git commit

第 7 步:如果在没有参数的情况下调用,应该打开默认的提交消息编辑器,其中包含一条不错的消息,解释合并和已解决的冲突(我相信)

Once you resolve the conflict and git add <conflicted file> when you go on to git 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.

  1. Commit to BranchB
  2. git checkout master
  3. git pull origin master
  4. git merge BranchB
  5. Resolve conflicts in file(s)
  6. git add <conflicted file(2)>
  7. 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文