git merge: Removing files I want to keep!

前端 未结 5 1408
别跟我提以往
别跟我提以往 2020-11-28 05:08

How can you merge two branches in git, retaining necessary files from a branch?

When merging two branches, if a file was deleted in one branch and not in an

5条回答
  •  囚心锁ツ
    2020-11-28 05:37

    You need to modify the file in the branch, so that there's a merge conflict with the delete in the trunk.

    The exact same thing will happen if you, for example, delete a declaration for something in a headerfile in the trunk (because nothing needs it), and add a dependency on that declaration to some non-header file(s) in the branch. When you merge, since the branch doesn't touch (that part of) the header, it will just delete the declaration and things will break.

    Whenever you have stuff in multiple places that is interdependent and needs to be kept in sync, its very easy for a merge to silently introduce problems. Its just one of the things you have to know about and check when merging. Ideally, you use compile-time asserts or other build time checks that will make any failures immediately apparent.

提交回复
热议问题