Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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)

like image 451
Mellon Avatar asked Mar 24 '11 15:03

Mellon


People also ask

What happens after merge conflict resolved?

merge : add ' --continue ' option as a synonym for ' git commit ' Teach ' git merge ' the --continue option which allows 'continuing' a merge by completing it. The traditional way of completing a merge after resolving conflicts is to use ' git commit '.

How do you automatic merge failed fix conflicts and then commit the result?

CONFLICT (content): Merge conflict in <fileName> Automatic merge failed; fix conflicts and then commit the result. This type of conflict can be resolved either by manually fixing all the merge conflict for each file OR using git reset ––hard (resets repository in order to back out of merge conflict situation).

How do you resolve a merge conflict without committing?

Resolve the conflict(s) manually or using some merge tool. Then use git reset to mark conflict(s) as resolved and unstage the changes. Also you can execute it without any parameters and Git will remove everything from the index. You don't have to execute git add before.


1 Answers

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.

like image 102
Cascabel Avatar answered Nov 15 '22 02:11

Cascabel