Git: How to manually manipulate/craft a merge between two branches when no conflict occurs
Say there’s a feature branch that we’ll refer to as branch
A contains three files,
A2 (main.css), and
B was created/checked out, giving
Now, say that all contents of
B3 where completely removed and totally different code was written then committed to branch
Say that the new code of all the files of branch
B will ultimately need to be integrated into the original code as a subset of it.
I expected to be able to achieve this integration of
B code into
A code by checking out branch
A and running
git merge B. I assumed that this would present me with a merge conflict with which I could craft new versions of
A3 to commit to branch
Git, however, did not produce the expected merge conflict and instead completely replaced all the
A code with the
- can we add merge --no ff in .gitattributes file without modifying gitconfigs
- why post-merge git hook not running?
- Merging another person's contributions with minor changes
- Move a file/directory but still merge changes easily?
- A way to automatically sync stable and develop branch in GitHub repo
- Git merging one branch into another is a two way merge?
How can the code of these two branches be integrated?
I realize one could copy code from the
B files and past it into the code of the
A files, all outside of Git. I consider that a less than ideal solution, though, because the project history won’t, then, reflect the fact that some of
A code came from
One Solution collect form web for “Git: How to manually manipulate/craft a merge between two branches when no conflict occurs”
If you have no new commit on branch
A then branch
B is a descendant of
A. Therefore a merge is (per default) done as a fast forward, i.e. no explicit merge commit is generated only
A is set to
B. (You could generate an explicit merge commit with
git merge --no-ff option.)
The idea of a merge is to integrate all the new changes to the old state. If the change is replacing the content of one file by something completely different, then integrating that change is done by doing exactly this on branch
A, which will result in the new content.
I currently cannot think of a situation where this is not what you want.