博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
本地Git关联远程Git时遇到的一些问题
阅读量:6489 次
发布时间:2019-06-24

本文共 3701 字,大约阅读时间需要 12 分钟。

hot3.png

情景,本地git与远程Git仓库同步

Administrator@EZ-20170513RQHH MINGW32 /d/workspace/learngit$ git initInitialized empty Git repository in D:/workspace/learngit/.git/Administrator@EZ-20170513RQHH MINGW32 /d/workspace/learngit (master)$ git remote add origin git@github.com:ZhuBaker/learngit.gitAdministrator@EZ-20170513RQHH MINGW32 /d/workspace/learngit (master)$ git push -u origin mastererror: src refspec master does not match any.error: failed to push some refs to 'git@github.com:ZhuBaker/learngit.git'

原因分析

引起该错误的原因是,目录中没有文件,空目录是不能提交上去的

解决方法

Administrator@EZ-20170513RQHH MINGW32 /d/workspace/learngit (master)$ touch READMYFILEAdministrator@EZ-20170513RQHH MINGW32 /d/workspace/learngit (master)$ git add READMYFILEAdministrator@EZ-20170513RQHH MINGW32 /d/workspace/learngit (master)$ git commit -m 'add READMYFILE'[master (root-commit) 28ed8af] add READMYFILE 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 READMYFILEAdministrator@EZ-20170513RQHH MINGW32 /d/workspace/learngit (master)$ git push -u origin masterTo github.com:ZhuBaker/learngit.git ! [rejected]        master -> master (fetch first)error: failed to push some refs to 'git@github.com:ZhuBaker/learngit.git'hint: Updates were rejected because the remote contains work that you dohint: not have locally. This is usually caused by another repository pushinghint: to the same ref. You may want to first integrate the remote changeshint: (e.g., 'git pull ...') before pushing again.hint: See the 'Note about fast-forwards' in 'git push --help' for details.

提示首先要fetch 代码  或者 git pull

或者是强推  git push -f

Administrator@EZ-20170513RQHH MINGW32 /d/workspace/learngit (master)$ git pull origin masterFrom github.com:ZhuBaker/learngit * branch            master     -> FETCH_HEADfatal: refusing to merge unrelated histories

提示拒绝merge两个不相关的git

因为他们是两个不同的项目,要把两个不同的项目合并,git需要添加一句代码,在git pull,这句代码是在git 2.9.2版本发生的,最新的版本需要添加--allow-unrelated-histories

假如我们的源是origin,分支是master,那么我们 需要这样写git pull origin master --allow-unrelated-histories需要知道,我们的源可以是本地的路径

Administrator@EZ-20170513RQHH MINGW32 /d/workspace/learngit (master)$ git pull origin master --allow-unrelated-historiesFrom github.com:ZhuBaker/learngit * branch            master     -> FETCH_HEADMerge made by the 'recursive' strategy. abc.txt | 0 dd      | 1 + ddd.txt | 0 3 files changed, 1 insertion(+) create mode 100644 abc.txt create mode 100644 dd create mode 100644 ddd.txtAdministrator@EZ-20170513RQHH MINGW32 /d/workspace/learngit (master)$ lsabc.txt  dd  ddd.txt  READMYFILE
Administrator@EZ-20170513RQHH MINGW32 /d/workspace/learngit (master)$ git pullThere is no tracking information for the current branch.Please specify which branch you want to merge with.See git-pull(1) for details.    git pull 
If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/
master

直接使用git pull 命令会提示该提示:

让我们使用 git pull 或者 建立本地分支与远程分支的关联才能使用

Administrator@EZ-20170513RQHH MINGW32 /d/workspace/learngit (master)$ git branch --set-upstream-to=origin/master masterBranch master set up to track remote branch master from origin.Administrator@EZ-20170513RQHH MINGW32 /d/workspace/learngit (master)$ git pullAlready up-to-date.Administrator@EZ-20170513RQHH MINGW32 /d/workspace/learngit (master)$ git pushCounting objects: 4, done.Delta compression using up to 4 threads.Compressing objects: 100% (3/3), done.Writing objects: 100% (4/4), 465 bytes | 0 bytes/s, done.Total 4 (delta 1), reused 0 (delta 0)remote: Resolving deltas: 100% (1/1), completed with 1 local object.To github.com:ZhuBaker/learngit.git   6af3724..c01f0f2  master -> master

 

 

 

 

转载于:https://my.oschina.net/LucasZhu/blog/1550827

你可能感兴趣的文章
HIbernate映射关系之一对一(双向)
查看>>
System Center 2012 SP1 Data Protection Manager 设置备份
查看>>
Python基础内容四
查看>>
烂泥:切割nginx日志
查看>>
Gitlab:从其它项目组里导入一个项目
查看>>
区块链技术的创新,对于区块链技术开发企业有哪些好处呢?
查看>>
Canny边缘检测算法的实现
查看>>
Android的应用(APP)启动详细流程
查看>>
外部网络通过端口映射访问部署在虚拟机里的docker中的web应用
查看>>
我的友情链接
查看>>
sudo(用户管理扩展)
查看>>
大数据集群高可用之 HDFS
查看>>
Mfs分布式文件系统
查看>>
Ubuntu14.04安装分布式存储sheepdog+zookeeper
查看>>
LVS+keepalived负载均衡(DR)
查看>>
三论计算机专业本科该如何学习——三要,三不要
查看>>
自行控制LoadRunner的socket协议性能测试
查看>>
Exchange Server 2010 outlook之Anywhere
查看>>
JavaScript之字符String
查看>>
Tcmalloc对Mysql及Nginx内存管理优化
查看>>