变更记录

序号 录入时间 录入人 备注
1 2016-07-21 Alfred Jiang -

方案名称

Git - 如何 clone git 项目到一个非空目录

关键字

Git \ clone git 非空目录

需求场景

  1. 对一个主工程的子工程进行单独的 Git 管理时

参考链接

  1. 开源中国 - 如何 clone git 项目到一个非空目录(推荐)

详细内容

如果我们往一个非空的目录下 clone git 项目,就会提示错误信息:

1
fatal: destination path '.' already exists and is not an empty directory.

解决的办法是:

  1. 进入非空目录,假设是 /workdir/proj1
  2. 执行以下命令
    1
    2
    3
    4
    git clone --no-checkout https://git.oschina.net/NextApp/platform.git tmp
    mv tmp/.git . #将 tmp 目录下的 .git 目录移到当前目录
    rmdir tmp
    git reset --hard HEAD

然后就可以进行各种正常操作了。

效果图

(无)

备注

(无)