how does git handle merging code that was moved to a different file?

前端 未结 4 614
花落未央
花落未央 2020-12-19 01:38

Say I have function X in file A, and I wanted to move that function to file B. In the meantime, somebody else made changes to function X in file A.

Does git do anyt

4条回答
  •  [愿得一人]
    2020-12-19 02:12

    I think the real situation is much more complex, but from what I have experienced, git can handle this kind of 3-way merge well.

    For example:

    One function of a File in branch A was moved to another location in the same file and meanwhile create a branch B to hold it. The difference between branch B and branch A is only the code location change in the same file.

    Branch C changed that function.

    So, if you do:

    $ git rebase --onto B A C

    It will automatically merge the change from branch C to the new location of that function in branch B.

提交回复
热议问题