码迷,mamicode.com
首页 > 其他好文 > 详细

Visual Studio Git本地Repos和GitHub远程Repos互操作

时间:2019-03-17 11:05:45      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:互操作   war   master   hint   art   而且   detail   ocs   ranch   

近期准备将一个项目开源到GitHub中,N-Sharding,.Net版本的分库分表数据访问框架。中间遇到了点小问题,整理了一下。

1. GitHub上Create New Repos

2. 代码Check In到本地Git Repos

3. Push到GitHub远程Repos

一、GitHub上Create New Repos:N-Sharding

技术图片

2. 代码Check In到本地Git Repos 

技术图片

 

3. Push到GitHub远程Repos

技术图片

推送提示一下错误:

将分支推送到远程存储库时遇到错误: rejected Updates were rejected because the tip of your current branch is behind its remote counterpart. Integrate the remote changes  before pushing again.
Error: failed to push some refs to https://github.com/*****/N-Sharding.git
Error: 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.

看中间第三句话:Updates were rejected because the tip of your current branch is behind

说明本地分支是旧的,远程Master分支要新。为什么呢?

突然想起来,在GitHub上Create New Repos时,增加了Readme.md。本地没有这个文件。

一顿百度后:https://www.cnblogs.com/gzdaijie/p/5186516.html

解决方案:

1. 打开Git Bash

2. Git拉取最新的代码到本地,一定要rebase,强制同步更新本地分支

git pull --rebase origin master

技术图片

关于Git rebase,可以参考:https://git-scm.com/docs/git-rebase

3. 推送Push到Master主分支

git push -u origin master

技术图片

Push 成功,代码成功提交到master。

Tips:关于git merge 与 git rebase

1. git merge 和 git rebase 都是将远程分支与本地分支合并的一种方法,git merge 会生成一个新的节点,例如A和B都位于同一个HEAD,A提交了2个commit C1和C2,B 提交了2个commit C3和C4,git merge的结果是在C3和C4之后合并生成C5,这样提交历史比较清晰,但多了一个C5
2. 假设A已经将C1和C2 push到了远程分支,那么B 使用git rebase则会将C3和C4缓存到.git/rebase中,恢复到之前的状态,更新C1和C2,然后再将C3和C4作为补丁应用到C2的状态上。结果如下:
原始状态->C1->C2->C3->C4,C3和C4为git 根据C3和C4生成的补丁,log是一条直线,而且没有多余的C5,但是平行信息丢失。

关于git pull 与 git pull --rebase

1. git pull = git fetch + git merge
2. git pull --rebase = git fetch + git rebase

 

以上,分享给大家。

 

周国庆

2019/3/17

 

Visual Studio Git本地Repos和GitHub远程Repos互操作

标签:互操作   war   master   hint   art   而且   detail   ocs   ranch   

原文地址:https://www.cnblogs.com/tianqing/p/10545294.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!