What's the best practice to “git clone” into an existing folder?

后端 未结 15 1492
情书的邮戳
情书的邮戳 2020-11-28 17:19

I have a working copy of the project, without any source control meta data. Now, I\'d like to do the equivalent of git-clone into this folder, and keep my local changes.

15条回答
  •  有刺的猬
    2020-11-28 17:49

    This is the Best of all methods i came across

    Clone just the repository's .git folder (excluding files as they are already in existing-dir) into an empty temporary directory

    1. git clone --no-checkout repo-path-to-clone existing-dir/existing-dir.tmp //might want --no-hardlinks for cloning local repo

    Move the .git folder to the directory with the files. This makes existing-dir a git repo.

    1. mv existing-dir/existing-dir.tmp/.git existing-dir/

    Delete the temporary directory

    1. rmdir existing-dir/existing-dir.tmp

    2. cd existing-dir

    Git thinks all files are deleted, this reverts the state of the repo to HEAD.

    WARNING: any local changes to the files will be lost.

    1. git reset --mixed HEAD

提交回复
热议问题