开发者

problem with commit message after conflicts been resolved when merge

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 confli开发者_如何学Ccts. 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)


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.


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜