情况就是这样。我们有一个带有项目的开发服务器。我在当地有相同的项目。该项目还没有存储库。文件是相等的,或者我们希望。i git init
使用SSH,git remote add
,git add .
文件,git commit -m
和git push -u origin master
。同样,在Sever 上。
现在,我不想git克隆整个存储库,因为我已经在本地拥有文件。是否有一种干净的方法可以在本地文件中以某种方式 git init
,这样我就不必git clone
整个项目,并且有一种方法可以很好地处理本地文件中与现在推送的服务器文件相比。P>
尝试使git的尝试不明白本地文件与服务器文件相同(在现在的在线存储库中),并说整个文件被覆盖。
任何帮助都将不胜感激。
此答案讨论了非常相似的用例。
基本想法是仅将.git
文件夹复制到您现有的项目根文件夹中。
以下示例直接从链接的答案中获取,可与git reset --hard HEAD
一起使用。如果您还想尝试使用本地更改,请尝试使用git reset HEAD
。
existing-dir
是您的本地目录,与repo-to-clone
存储库中的文件匹配。
# Clone just the repository's .git folder (excluding files as they are already in # `existing-dir`) into an empty temporary directory git clone --no-checkout repo-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. mv existing-dir/existing-dir.tmp/.git existing-dir/ # Delete the temporary directory rmdir existing-dir/existing-dir.tmp 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. git reset --hard HEAD