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.
Branch A contains three files, A1 (index.html), A2 (main.css), and A3 (script.js).
From branch A, branch B was created/checked out, giving B1, B2, and B3.
Now, say that all contents of B1B3 where completely removed and totally different code was written then committed to branch B.
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 A1A3 to commit to branch A.
Git, however, did not produce the expected merge conflict and instead completely replaced all the A code with the B code.

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 B.

  • How do I separate a commit into a branch after doing several other commits?
  • How to see exactly what happend in git merge
  • Git merge different file names
  • Manually merge git pull request
  • How do I retrieve lost changes in a git repo?
  • Merging in git after changing file name capitalization
  • Maintain branches in GIT without merging with master
  • git revert merge - neither mainline looks correct
  • 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.

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