I've a master branch in which there is a file Demo.txt. It has the following 2 lines:
AAAAAA
BBBBBB
A new branch Dev is branched off from the master at this point. The branch Dev now contains Demo.txt with the same 2 lines i.e
AAAAAA
BBBBBB
Lets suppose I checkout master and add a new line to Demo.txt so that the file becomes :
AAAAAA
BBBBBB
XXXXXX
Similarly, I then checkout Dev and add a new line to Demo.txt so that the file becomes:
AAAAAA
BBBBBB
YYYYYY
Now I checkout master and merge Dev into it. There is a merge conflict on file Demo.txt in the 3rd line. Lets suppose the conflict is resolved by keeping entries of both master and Dev branch. Lets suppose the new merged file looks like :
AAAAAA
BBBBBB
XXXXXX
YYYYYY
Now I commit the merge and push it to the remote repository. Let us suppose the commit id of the merge is something like abcdef056fg(only an example). After pushing the merge I discover that there has been some error in resolving the merge conflict and I want to roll back the merge.Also, I want to add one more change to Dev as part of the error fix before merging it to master again.According to the guidelines given in this link by Linus Torvalds - "https://raw.githubusercontent.com/git/git/master/Documentation/howto/revert-a-faulty-merge.txt" , I revert the revert of the merge abcdef056fg. For example, I checkout master,do "revert -m 1 abcdef056fg" which gives me a new commit.I revert the commit again to get the revert of the revert. The revert of revert merge gives me the following Demo.txt:
AAAAAA
BBBBBB
XXXXXX
YYYYYY
I then checkout Dev and add a new file Demo2.txt to it with the following lines;
PPPPPP
I now checkout master and merge Dev again. The new file Demo2.txt is merged correctly into master. But I'm not given the option of resolving the merge conflict of Demo.txt again. Lets suppose I wanted the merge conflict to show up again in Demo.txt so that I could change it to the following:
AAAAAA
BBBBBB
YYYYYY
XXXXXX
instead of
AAAAAA
BBBBBB
XXXXXX
YYYYYY
How do I do it. I don't want to make changes directly on my master because I keep my master branch clean and do not do any development on it. All development is done in the Dev branch and it is finally tested and merged into the master. Also this is a contrived example with a single conflict. Any such merge might have several conflicts which were resolved and committed and I would not like to fix all those in the master. So how do I do it?
I found the answer to this question.The answer lies in the fact that there is an obvious error in which the above merge was carried out.I mentioned that my intention was to keep the master branch always clean with no development but I added the 3rd line XXXXXX to Demo.txt in master before the first merge.This is a contradiction. Now having added XXXXXX, I should have first merged master into Dev before merging Dev back into master.Doing the prior would have given merge conflicts in Demo.txt which would have been resolved as per requirement as follows:
AAAAAA
BBBBBB
XXXXXX
YYYYYY
If I then merged back into master it would have been a straight forward merge with Demo.txt in master remaining as:
AAAAAA
BBBBBB
XXXXXX
YYYYYY
Now reverting the revert in master would have kept Demo.txt same as above. Now if I checked out Dev for the bug fix(apart from adding Demo2.txt) and fixed Demo.txt as follows:
AAAAAA
BBBBBB
YYYYYY
XXXXXX
and checked out master again and merged Dev into master, git would fix Demo.txt in master with the following four lines without giving merge conflicts :
AAAAAA
BBBBBB
YYYYYY
XXXXXX
This solves our purpose.
Not deleting the question because this might be some useful analysis.