25

Is there a way in git to merge two branches without merging file? In other words just to draw the merge arrow.

Let say I have branches A and B. I need to merge branch B to A, but no need all the changes in B, but rather only need to link to branches together.

git checkout A
git merge B --no need changes

In general is there a way to merge two branches without submodules. I want to keep submodules as it is in Branch A and still need to merge branch B.

inetphantom
  • 2,498
  • 4
  • 38
  • 61
Ishan Liyanage
  • 2,237
  • 1
  • 26
  • 25
  • 1
    What do you mean by _"without merging the file"_? – 1615903 Jun 15 '16 at 10:55
  • What do you mean with just draw the merge arrow? A commit that has as parents the last commit in the two branches but the tree of one of the branches? Maybe you can describe your use case? – gregor Jun 15 '16 at 10:58
  • I just only need to create the commit graph. In other words just need to draw a merge arrow without actually merging two versions together – Ishan Liyanage Jun 15 '16 at 11:20
  • 4
    It sounds like you are asking for `git merge -s ours B`, but your description is not entirely clear. – torek Jun 15 '16 at 11:47
  • 2
    Possible duplicate of [GIT: How to 'overwrite', rather than 'merge', a branch on another branch](http://stackoverflow.com/questions/4624357/git-how-to-overwrite-rather-than-merge-a-branch-on-another-branch) – Joe Jun 15 '16 at 12:01
  • I don't think you want to actually `merge` here. Can you explain what the result you're expecting is? – Nils Werner Jun 15 '16 at 12:33
  • I have updated the question. – Ishan Liyanage Jun 16 '16 at 02:10

2 Answers2

40

Use git merge -s ours B to perform a merge discarding any changes B would introduce. Still, the commits from B are now in A, however, the files are at the state of A before the merge.

Jonas Schäfer
  • 20,140
  • 5
  • 55
  • 69
1

You can do a real merge and run git reset ORIG_HEAD --hard to go back.

If you just want to have a try or study what happens after git merge, you could make a series empty commits by git commit --allow-empty --allow-empty-message --no-edit for several times. After you create the commits and branches, you can run git merge and use gitk or git log --oneline --graph to see the commit graphic.

ElpieKay
  • 27,194
  • 6
  • 32
  • 53