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

  • In a Git repository, how to properly rename a directory?
  • Where do commit ids come from?
  • Reasons for not working on the master branch in Git
  • Git: How to ignore fast forward and revert origin to earlier commit?
  • How to make git push run faster
  • Github: Unable to sync pages directory
  • 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)

  • Git push to wrong branch
  • Adding part of a hunk interactively with git add --patch
  • Remove refs/original/heads/master from git repo after filter-branch --tree-filter?
  • How can I make git tell curl to use openssl instead of gnutls without rebuilding the package?
  • Checking Out a Branch in Git
  • Graphic tool to display element tree branch in git for linux
  • 2 Solutions collect form web for “problem with commit message after conflicts been resolved when merge”

    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)

    Git Baby is a git and github fan, let's start git clone.