Git使用的一个注意事项--删除文件后的rebase/merge导致文件丢失

代码衍合过程中发现的一个问题:

只要在某个分支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

鉴于以上的结论,建议在开发过程中应该避免删除操作。除非确定所有分支都不会再用到。

转载于:https://my.oschina.net/zhuguowei/blog/408261

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值