代码衍合过程中发现的一个问题:
只要在某个分支A中删除了某个文件(如file1)且另外一个分支B也包含此文件,则分支B rebase或merge 分支A时会丢失该文件。
如下所示:
$ mkdir temp
$ cd temp
$ touch file1
$ git init
$ git add .
$ git commit -m 'first commit in master'
$ ls
file1
$ git checkout -b bran-1
$ git checkout -b bran-2
$ git checkout bran-1
$ ls
file1
$ rm file1
$ touch file2
$ git add --all
$ git commit -m 'first commit in bran-1'
[bran-1 709dc71] first commit in bran-1
1 file changed, 0 insertions(+), 0 deletions(-)
rename file1 => file2 (100%)
$ git checkout bran-2
$ touch file3
$ ls
file1 file3
$ git add .
$ git commit -m 'first commit in bran-2'
$ git rebase bran-1
#file1丢失了
$ ls
file2 file3
鉴于以上的结论,建议在开发过程中应该避免删除操作。除非确定所有分支都不会再用到。