如何在不进行git克隆的情况下同步新的GIT存储库本地文件

时间:2019-03-13 10:14:17

标签: git github gitlab

情况是这样;我们有一个开发服务器,上面有我们的项目。我在本地有相同的项目。该项目还没有存储库。文件是相等的,所以我们希望如此。我使用SSH git initgit remote addgit add .文件,git commit -mgit push -u origin master git init服务器文件。再次,断开服务器

现在,我不想git克隆整个存储库,因为我已经在本地存储了文件。有没有一种干净的方法可以在本地文件中以某种方式git clone,这样我就不必from keras.layers import Activation, Input, Dense from keras.models import Model from keras.layers.merge import Concatenate, concatenate input_ = Input(batch_shape=(512, 36)) x = input_ x1 = Dense(4)(x) x2 = Dense(4)(x) x3 = Dense(4)(x) x4 = Dense(4)(x) model = Model(inputs=input_, outputs=[x1, x2, x3, x4]) model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) history = model.fit(X, test, epochs=20, batch_size=512, verbose=2, shuffle=False, validation_data=[X, test]) 整个项目,并且有一种方法可以很好地处理本地文件中的所有可能差异,与现在推送的服务器文件。

到目前为止,这种尝试使git无法理解本地文件与服务器文件相同(在现在的在线仓库中),并说整个文件都被覆盖了。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

answer讨论了一个非常相似的用例。

基本思想是仅将.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