首页 > 解决方案 > 将另一台服务器上的单个文件添加到 git 存储库

问题描述

我在要添加到远程存储库的数据库服务器上创建了一个脚本。

我在 SQL 模式脚本存在的目录中执行了以下操作

git init
git remote add origin https://my@bitbucket.org/me/myproject.git
git add schema.sql
git commit -m "added schema.sql"

当我这样做时,git push我会得到以下信息

fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

当我这样做时,git push --set-upstream origin master我得到

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://my@bitbucket.org/me/myproject.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我想将此单个文件添加到我的远程存储库中。有没有一种简单的方法可以用 git 做到这一点?

标签: git

解决方案


而不是git init && git remote add ...使用:

git clone https://my@bitbucket.org/me/myproject.git

然后将您的文件放在它所属的位置,然后:

git add schema.sql
git commit -m "added schema.sql"
git push

如果您需要将此文件推送到已建立的仓库,那么您需要拉取:

git init
git remote add origin https://my@bitbucket.org/me/myproject.git
git pull
git add schema.sql
git commit -m "added schema.sql"

推荐阅读