2

作为我的任务的一部分,我需要将组件从三个地方合并到一个地方。换句话说,将文件夹(包括许多子文件夹和文件)移动到一个现有文件夹。

我正在使用git mv,但问题是,一旦我尝试将git merge非合并分支合并(使用)到合并分支,我会遇到很多冲突,其中大部分与 Git 刚刚移动到错误位置的文件有关.

知道为什么 Git 不知道如何正确处理它吗?(Git 版本是最新的。)

示例

合并前:

│   └── dir1
│   │   └── python1
│   │   │   └── test1.py
│   └── dir2
│   │   └── python2
│   │   │   └── test2.py
│   └── dir3
│   │   └── python3
│   │   │   └── test3.py

合并后:

│   └── dir1
│   └── dir2
│   │   └── python1
│   │   │   └── test1.py
│   │   └── python2
│   │   │   └── test2.py
│   │   └── python3
│   │   │   └── test3.py
│   └── dir3

合并前(目标树):

│   └── dir1
│   │   └── python1
│   │   │   └── test1.py
│   │   │   └── test4.py

合并后:

│   └── dir1
│   └── dir2
│   │   └── python1
│   │   │   └── test1.py
│   │   └── python2
│   │   │   └── test2.py
│   │   │   └── test4.py
│   │   └── python3
│   │   │   └── test3.py
│   └── dir3

更新

我正在添加一个答案似乎不支持的案例:

合并后的源码树:

│   └── dir1
│   └── dir2
│   │   └── python1
│   │   │   └── test1.py
│   │   └── python2
│   │   │   └── test2.py
│   │   └── python3
│   │   │   └── test3.py
│   └── dir3

合并前(目标树):

│   └── dir1
│   │   └── python1
│   │   │   └── test1.py
│   │   │   └── test4.py
|   |   |   └── new_test
│   │   │       └── test5.py

合并后(使用ORT答案中的命令):

│   └── dir1
│   │   └── python1
|   |   |   └── new_test
│   │   │       └── test5.py
│   └── dir2
│   │   └── python1
│   │   │   └── test1.py
│   │   │   └── test4.py
│   │   └── python2
│   │   │   └── test2.py
│   │   └── python3
│   │   │   └── test3.py
│   └── dir3

如您所见,它检测到新文件及其新位置(test4.py),但没有检测到新文件夹(使用 test5.py)。我希望它也会将它移动到 python2 下的新位置,因为文件(test4.py)和文件夹(`new_test)都具有相同的父级(python1)。我将与 GIT 支持团队核对并更新

4

1 回答 1

0

答案与此线程中的相同(我写的时候没有意识到): https ://stackoverflow.com/a/69114710/11705021

于 2021-09-19T21:00:43.010 回答