GIT将本地更改合并到远程
我有一个远程存储库。我直接从运行应用程序的服务器(不是从git克隆的)复制了代码,并做了一些更改和添加了一些文件。现在,我想将代码推送到远程存储库,但它将我抛出上述错误 当我做git pull时,这里是GIT将本地更改合并到远程,git,github,version-control,Git,Github,Version Control,我有一个远程存储库。我直接从运行应用程序的服务器(不是从git克隆的)复制了代码,并做了一些更改和添加了一些文件。现在,我想将代码推送到远程存储库,但它将我抛出上述错误 当我做git pull时,这里是 ``*分支头->取头 致命:拒绝合并不相关的历史记录 错误这就是我要做的 假设您已将代码复制到~/copied中 运行以下命令 To https://github.com/prakashperam/myrepo ! [rejected] master -&
``*分支头->取头 致命:拒绝合并不相关的历史记录
错误这就是我要做的 假设您已将代码复制到~/copied中 运行以下命令
To https://github.com/prakashperam/myrepo
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to
'https://github.com/prakashperam/myrepo.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
这是为什么。为什么使用复制而不是克隆?您想保留远程repo的提交历史记录还是本地repo的提交历史记录?因为服务器中的代码和github中的代码是相互关联的。但是,服务器代码是最新的,并且有许多更改没有推送到github。如果您有一个具有多个提交的不同存储库,您可以尝试合并存储库。但是,如果您有一个专门使用当前版本代码的一次提交创建的存储库,那么它没有任何价值:克隆原始版本,将当前版本复制到工作树中,并将当前版本作为一次新提交提交。您将能够使用新存储库并使其与旧存储库相匹配,并且通过将错误存储库中的单个提交更改为正确存储库中的单个提交,您不会丢失任何内容。
git clone https://github.com/prakashperam/myrepo ~/cloned
cd ~/cloned
git remote add localcopy ~/copied/.git
git rebase localcopy master
git push