Git:从github上传到已部署的服务器

时间:2018-05-09 09:48:04

标签: git github

该项目是在本地计算机上开发的,然后 git push 命令将更改发送到github。之后, git clone 命令项目已部署到服务器。一切正常。现在我在本地计算机上进行了新的更改,将它们复制到gitgub,我想将它们发送到生产服务器。再做一次

git clone https://github.com/myaccount/site

我收到错误

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

我应该使用哪个命令?

UPD

git pull之后我得到了错误

error: Your local changes to the following files would be overwritten by merge:
    album/api/serializers.py
    album/api/urls.py
    album/api/views.py
    customuser/models.py
    entertainment/forms.py
    places/models.py
    places/urls.py
    places/views.py
    templates/places/places_list.html
    templates/vtv/video.html
    vtoday/settings/base.py
    vtoday/urls.py
    vtv/models.py
    vtv/urls.py
    vtv/views.py
Please commit your changes or stash them before you merge.
error: The following untracked working tree files would be overwritten by merge:
    entertainment/migrations/0012_remove_entertainment_main_photo.py
    media/places/pexels-photo-373965.jpeg
    places/api/__init__.py
    places/api/serializers.py
    places/api/urls.py
    places/api/views.py
    places/filters.py
Please move or remove them before you merge.
Aborting

2 个答案:

答案 0 :(得分:1)

错误消息是不言自明的,您正在尝试将存储库克隆到非空目录中。

然而,要检索需要使用pull命令的更改,您不需要再次克隆存储库,还需要先提交现有更改,以便将它们与那些你将从服务器拉出的东西:

git add . --all
git commit -m "Add a description"
git pull

如果您没有任何冲突,您的文件将自动合并。

然后将所有内容推送到远程服务器:

git push

有关其他选项,请参阅此问题:How do I resolve git saying "Commit your changes or stash them before you can merge"?

修改

你有一个合并问题:

  

自动合并   娱乐/迁移/ 0012_remove_entertainment_main_photo.py   CONFLICT(添加/添加):合并冲突   娱乐/迁移/ 0012_remove_entertainment_main_photo.py   自动合并失败;修复冲突,然后提交结果

这意味着两个存储库都修改了文件的相同部分0012_remove_entertainment_main_photo.py

如果您只想将文件保留在服务器中,只需发出以下命令:

git reset entertainment/migrations/0012_remove_entertainment_main_photo.py

这将删除您在本地存储库中对此文件所做的任何更改

如果您想手动合并文件,请查看此问题How to resolve merge conflicts in Git?

答案 1 :(得分:1)

要从远程(在您的github案例中)获取更改,您应该使用git pull。另一个选项是here 每个repo副本只进行一次克隆。

此外:如果您的遥控器和本地文件系统上的文件已更改,则会导致冲突。如果您想在不提交的情况下保留本地更改,可以使用:

git stash
git pull
git stash pop

如果您想提交当前更改,请执行以下操作:

git commit --all -m "My Message"
git pull

如果您只想丢弃本地更改,请使用:

git reset --hard

但是可能会有未经跟踪的更改(目前不在您的仓库中的文件),可以通过以下方式删除:

git clean -fd 

如果可能的话,git会自动合并这些更改,但它可能导致手动合并,这意味着你必须告诉git哪个"版本"你想保留。