git - 将另一台服务器上的单个文件添加到 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 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"
推荐阅读
- sql-server - 如何处理一个维度中跨 SQL Server 数据库表的相似字段
- javascript - Reassign JavaScript variable via destructuring
- css - 在 css 中选择每行*的第一个子 * 并带有包装的弹性框(第一列?)
- java - 在某些条件下最大化 GCD
- vue.js - 带有 Vue 的电子禁用自动重新加载
- c - 尽管已经定义了函数体,但编译器警告“隐式声明”
- vuejs2 - 将 vue2-editor 视图内容切换为 html
- bash - Bash 中的简单 For 循环
- google-maps - 谷歌地图更新 url LatLngBounds 并在相机移动时缩放
- java - 如何在 JavaFX 中为 3D 框设置 LinearGradient