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
- How to get rid of Merge commits in git
- How do I fix 'bus error' when trying to do git-commit or git-status
- Adding to git staging means what?
- Git: Weird phenomenon in commit conflict
- Are there any real differences between using “fixup!” or “squash!”?
- Git log and reality mismatch
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)
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
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.
- Commit to BranchB
git checkout master
git pull origin master
git merge BranchB
- Resolve conflicts in file(s)
git add <conflicted file(2)>
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)