<div id="article_details" class="details">
<div class="article_title">
<span class="ico ico_type_Repost"></span>
<h1>
<span class="link_title"><a href="/sunayxin/article/details/74078228">
GIT学习总结
</a>
</span>
</h1>
</div>
<div class="article_manage clearfix">
<div class="article_r">
<span class="link_postdate">2017-07-01 18:24</span>
<span class="link_view" title="阅读次数">39人阅读</span>
<span class="link_comments" title="评论次数"> <a href="#comments" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_pinglun'])">评论</a>(0)</span>
<span class="link_collect tracking-ad" data-mod="popu_171"> <a href="javascript:void(0);" οnclick="javascript:collectArticle('GIT%e5%ad%a6%e4%b9%a0%e6%80%bb%e7%bb%93','74078228');return false;" title="收藏" target="_blank">收藏</a></span>
<span class="link_report"> <a href="#report" οnclick="javascript:report(74078228,2);return false;" title="举报">举报</a></span>
</div>
</div> <style type="text/css">
.embody{
padding:10px 10px 10px;
margin:0 -20px;
border-bottom:solid 1px #ededed;
}
.embody_b{
margin:0 ;
padding:10px 0;
}
.embody .embody_t,.embody .embody_c{
display: inline-block;
margin-right:10px;
}
.embody_t{
font-size: 12px;
color:#999;
}
.embody_c{
font-size: 12px;
}
.embody_c img,.embody_c em{
display: inline-block;
vertical-align: middle;
}
.embody_c img{
width:30px;
height:30px;
}
.embody_c em{
margin: 0 20px 0 10px;
color:#333;
font-style: normal;
}
</style>
<script type="text/javascript">
$(function () {
try
{
var lib = eval("("+$("#lib").attr("value")+")");
var html = "";
if (lib.err == 0) {
$.each(lib.data, function (i) {
var obj = lib.data[i];
//html += '<img src="' + obj.logo + '"/>' + obj.name + " ";
html += ' <a href="' + obj.url + '" target="_blank">';
html += ' <img src="' + obj.logo + '">';
html += ' <em><b>' + obj.name + '</b></em>';
html += ' </a>';
});
if (html != "") {
setTimeout(function () {
$("#lib").html(html);
$("#embody").show();
}, 100);
}
}
} catch (err)
{ }
});
</script>
<div class="category clearfix">
<div class="category_l">
<img src="http://static.blog.csdn.net/images/category_icon.jpg">
<span>分类:</span>
</div>
<div class="category_r">
<label>
<span οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_fenlei']);">GIT<em></em></span>
</label>
</div>
</div>
<div id="article_content" class="article_content tracking-ad" data-mod="popu_307" data-dsm="post">
<h1 class="postTitle" style="margin:0px; padding:0px; position:relative; width:760px; border:none; font-family:微软雅黑">
<a target="_blank" id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/zyf-zhaoyafei/p/4486220.html" style="margin:0px; padding:0px; color:rgb(106,99,82); font-family:微软雅黑,华文细黑,黑体,Arial; font-size:18px; font-weight:normal">git学习总结</a></h1>
<div class="clear" style="margin:0px; padding:0px; clear:both; font-family:微软雅黑">
</div>
<div class="postBody" style="margin:10px 0px 0px; padding:0px; position:relative; width:760px; height:auto; border:none; color:rgb(73,73,73); font-size:14px; line-height:1.6">
<div id="cnblogs_post_body" style="margin:0px 0px 20px; padding:0px; background-color:transparent; word-break:break-word">
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px">git remote rename github gh</p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">最近学习学习git,总结了一点关于git的使用命令和遇到的问题</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">众所周知,Git是目前世界上最先进的分布式版本控制系统。下面说下git的使用知识</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:18px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">一、SVN与Git的最主要的区别?</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px"> <span style="margin:0px; padding:0px; font-size:14px"> 说起git自然想到<span style="margin:0px; padding:0px; color:rgb(0,128,0)">SVN</span>,我刚接触到的版本控制工具是SVN,<span style="margin:0px; padding:0px; color:rgb(0,128,0)">SVN是集中式版本控制系统,版本库是集中放在中央服务器的</span>,干活的时候,先要从中央服务器哪里得到最新的版本,干完活后,需要把自己做完的活推送到中央服务器。中央服务器就好比是一个图库,你要改一本书,必须先从图库借出来,然后回到家自己改,改完了,再放回图库。集中式版本控制系统是必须联网才能工作,如果在局域网还可以,带宽够大,速度够快,如果在互联网下,如果网速慢的话,就耽误事了。</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> Git是分布式版本控制系统,它没有中央服务器的,<span style="margin:0px; padding:0px; color:rgb(0,128,0)">每个人的电脑就是一个完整的版本库,</span>工作的时候就不需要联网了,因为版本都是在自己的电脑上。既然每个人的电脑都有一个完整的版本库,那多个人如何协作呢?比如说自己在电脑上改了文件A,其他人也在电脑上改了文件A,这时,你们两之间只需把各自的修改推送给对方,就可以互相看到对方的修改了。</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 和集中式版本控制系统相比,分布式版本控制系统的安全性要高很多,因为每个人电脑里都有完整的版本库,某一个人的电脑坏掉了不要紧,随便从其他人那里复制一个就可以了。而集中式版本控制系统的中央服务器要是出了问题,所有人都没法干活了。</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">Git基本常用命令如下:</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:18px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">二、常用的git命令</span></span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">--文件目录操作命令</span></span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span> <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">mkdir</span> **: 创建一个空目录 **<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">指目录名
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span> <span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">pwd: 显示当前目录的路径。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">3</span> cat ** 查看**<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">文件内容
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">4</span> git rm ** 删除**文件</span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">--git初始化操作</span></span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span> git init 把当前的目录变成可以管理的git仓库,生成隐藏.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">git文件。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span> git remote add origin https:<span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">//</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">github.com/git/librarysystem.git 把本地仓库的内容推送到GitHub仓库。</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">3</span> git <span style="margin:0px; padding:0px; color:rgb(0,0,255); font-size:12px!important; line-height:1.5!important">clone</span> git@github.com:michaelliao/gitskills.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">git 从远程库克隆
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">4</span> git add **<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> 把xx文件添加到暂存区去。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">5</span> git commit –m "**" 提交文件 –m 后面的是注释。</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:14px; line-height:1.5!important"><span style="margin:0px; padding:0px; font-family:"Courier New"!important; font-size:13px; line-height:1.5!important"> </span> </span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">--git 克隆分支</span></span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">1</span> git <span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">clone</span> xxx.git <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">//</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">最简单直接的命令</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">2</span> git <span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">clone</span> xxx.git "指定目录" <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">//</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">clone到指定目录</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">3</span> git <span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">clone</span> -b [new_branch_name] xxx.git <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">//</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">clone时创建新的分支替代默认Origin HEAD(master)</span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px; line-height:19px; color:rgb(75,75,75); font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; line-height:18px; font-family:"Microsoft YaHei"; font-size:15px; color:rgb(0,0,0)">--clone 远程分支</span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px; line-height:19px; color:rgb(75,75,75); font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="margin:0px; padding:0px; line-height:18px; font-family:"Microsoft YaHei"; font-size:14px; color:rgb(0,0,0)"> <span style="margin:0px; padding:0px">git clone 命令默认的只会建立master分支</span>,如果你想clone指定的某一远程分支(如:dev)的话,可以如下:</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px; line-height:19px; color:rgb(75,75,75); font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="margin:0px; padding:0px; line-height:18px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:14px; color:rgb(0,0,0)"> 1. 查看所有分支(包括隐藏的) </span><span style="margin:0px; padding:0px; line-height:19px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:14px; color:rgb(0,0,0)">git
branch -a 显示所有分支</span><span style="margin:0px; padding:0px; line-height:18px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:14px; color:rgb(0,0,0)"> </span> </span></span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">1</span> *<span style="margin:0px; padding:0px; line-height:1.5!important"> master
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">2</span> remotes/origin/HEAD -> origin/<span style="margin:0px; padding:0px; line-height:1.5!important">master
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">3</span> remotes/origin/<span style="margin:0px; padding:0px; line-height:1.5!important">dev
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">4</span> remotes/origin/master</pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px; line-height:19px; color:rgb(75,75,75); font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:14px; color:rgb(0,0,0)"> 2. <span style="margin:0px; padding:0px">在本地新建同名的("dev")分支,并切换到该分支</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">1</span> git checkout -t origin/<span style="margin:0px; padding:0px; line-height:1.5!important">dev 该命令等同于:
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">2</span> git checkout -b dev origin/dev</pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px">--查看命令</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span> <span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">git status 查看仓库状态
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span> git diff **<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> 查看XX文件修改了那些内容
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">3</span> git <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">log</span><span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> 查看历史记录
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">4</span> git reflog 查看历史记录的版本号id(记录你的每一次命令,<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">不论是否提交)
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">5</span> git <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">log</span> --pretty=oneline 如果信息量太多可以进行比较好的列表显示</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:14px; line-height:1.5!important"><span style="margin:0px; padding:0px; font-family:"Courier New"!important; font-size:13px; line-height:1.5!important"> </span> </span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px">--版本回退</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span> git <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">reset</span> –hard HEAD^ 或者 git <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">reset</span> --hard HEAD~<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> 回退到上一个版本
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span> (如果想回退到80个版本,使用git <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">reset</span> –hard HEAD~80 git <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">reset</span> --hard 版本号)</span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px">--撤销修改</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 1</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">checkout
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 2</span> <span style="margin:0px; padding:0px; line-height:1.5!important">恢复某个已修改的文件(撤销未提交的修改):
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 3</span> $ <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git checkout file-name
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 4</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 5</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">revert
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 6</span> <span style="margin:0px; padding:0px; line-height:1.5!important">还原已提交的修改(已经提交过的修改)
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 7</span> <span style="margin:0px; padding:0px; line-height:1.5!important">还原最近一次提交的修改:
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 8</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,0,0); line-height:1.5!important">$</span> git revert HEAD
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 9</span> <span style="margin:0px; padding:0px; line-height:1.5!important">还原指定版本的修改:
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">10</span> $ <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git revert commit-id</span></pre>
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px">--分支管理</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important">git push –u(第一次要用-<span style="margin:0px; padding:0px; line-height:1.5!important">u 以后不需要) origin master 把当前master分支推送到远程库
git branch 查看本地所有的分支<br style="margin:0px; padding:0px">git branch -a 查看远程<span style="margin:0px; padding:0px; line-height:1.5!important">所有的</span>分支
git branch name 创建分支<br style="margin:0px; padding:0px">
git checkout — </span>**<span style="margin:0px; padding:0px; line-height:1.5!important"> 把XX文件在工作区的修改全部撤销。
git checkout –b dev 创建dev分支 并切换到dev分支上
git checkout master 切换回master分支<br style="margin:0px; padding:0px">
git branch –d dev 删除dev分支
git merge dev 在当前的分支上合并dev分支
git push </span>--<span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">set</span>-<span style="margin:0px; padding:0px; line-height:1.5!important">upstream origin dev 提交修改并创建远程分支dev
git push origin zyf</span>-dev 把当前的分支 zyf-dev 推送到远程(远程仓库没有给分支则会新建立该分支)<br style="margin:0px; padding:0px"><br style="margin:0px; padding:0px">git merge dev 在当前分支上合并dev分支代</pre>
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px">--隐藏的文件</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span> <span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">git stash 把当前的工作隐藏起来 等以后恢复现场后继续工作
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span> git stash <span style="margin:0px; padding:0px; color:rgb(0,0,255); font-size:12px!important; line-height:1.5!important">list</span><span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> 查看所有被隐藏的文件列表
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">3</span> <span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">git stash apply 恢复被隐藏的文件,但是内容不删除
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">4</span> <span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">git stash drop 删除文件
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">5</span> git stash pop 恢复文件的同时 也删除文件</span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px">--查看远程库信息(git remote的用法)</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""><span style="margin:0px; padding:0px; font-size:15px"> </span></span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; font-family:"Courier New"!important; font-size:12px!important; line-height:1.5!important; color:rgb(0,128,0)">1</span> git remote 查看远程库的信息
<span style="margin:0px; padding:0px; font-family:"Courier New"!important; font-size:12px!important; line-height:1.5!important; color:rgb(0,128,0)">2</span> git remote –v 查看远程库的详细信息</span><br style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:14px; line-height:1.5!important"><span style="margin:0px; padding:0px; font-family:"Courier New"!important; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">3</span> git remote add name url 添加远程仓库<br style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">4</span> git remote rename oldname newname 重命名仓库<br style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">5</span> git remote rm 删除仓库<code style="margin:0px; padding:0px"></code></span><br style="margin:0px; padding:0px"></span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px">--将远程分支拉取到本地<span style="margin:0px; padding:0px; font-size:14px"><span style="margin:0px; padding:0px; font-size:15px"><br style="margin:0px; padding:0px">
</span></span></span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">1</span> 方法一:<span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git checkout -b 本地分支名x origin/远程分支名x
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">2</span> 方式二:<span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git fetch origin 远程分支名x:本地分支名x</span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-size:15px">--git pull操作</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 1</span> <span style="margin:0px; padding:0px; line-height:1.5!important">git pull命令的作用是,取回远程主机某个分支的更新,再与本地的指定分支合并,基本的格式如下。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 2</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">$ git pull <远程主机名> <远程分支名>:<本地分支名></span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 3</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 4</span> <span style="margin:0px; padding:0px; line-height:1.5!important">取回origin主机的next分支,与本地的master分支合并,需要写成下面这样
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 5</span> <span style="margin:0px; padding:0px; line-height:1.5!important">$ <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git pull origin next:master
</span></span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 6</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 7</span> <span style="margin:0px; padding:0px; line-height:1.5!important">如果远程分支是与当前分支合并,则冒号后面的部分可以省略。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 8</span> <span style="margin:0px; padding:0px; line-height:1.5!important">$ <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git pull origin next
</span></span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 9</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">10</span> 上面命令表示,取回origin/<span style="margin:0px; padding:0px; line-height:1.5!important">next分支,再与当前分支合并。实质上,这等同于先做git fetch,再做git merge。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">11</span> <span style="margin:0px; padding:0px; line-height:1.5!important">$ <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git fetch origin
</span></span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">12</span> $ <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git merge origin/next
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">13</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">14</span> 在某些场合,Git会自动在本地分支与远程分支之间,建立一种追踪关系(tracking)。比如,在git clone的时候,所有本地分支默认与远程主机的同名分支,建立追踪关系,也就是说,本地的master分支自动”追踪”origin/<span style="margin:0px; padding:0px; line-height:1.5!important">master分支。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">15</span> <span style="margin:0px; padding:0px; line-height:1.5!important">Git也允许手动建立追踪关系。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">16</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git branch --set-upstream master origin/next
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">17</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">18</span> 上面命令指定master分支追踪origin/<span style="margin:0px; padding:0px; line-height:1.5!important">next分支。如果当前分支与远程分支存在追踪关系,git pull就可以省略远程分支名。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">19</span> $ <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git pull origin</span></pre>
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-size:15px; font-family:"Microsoft YaHei"">--git 设置大小写敏感</span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px">Windows上的Git默认是大小写不敏感的,这样多平台写作就可能会出现问题。Win上的Git设置为大小写敏感的命令如下</p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">1</span> git config core.ignorecase <span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">false</span> </pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-size:15px; font-family:"Microsoft YaHei"">--git 设置忽略文件或文件夹权限修改</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">1</span> git config core.filemode <span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">false</span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-size:15px; font-family:"Microsoft YaHei""><span style="margin:0px; padding:0px">--创建追踪分支</span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; color:rgb(0,0,0)">不带任何参数的git push,默认只推送当前分支,这叫做simple方式。此外,还有一种matching方式,会推送所有有对应的远程分支的本地分支。Git 2.0版本之前,默认采用matching方法,现在改为默认采用simple方式。如果要修改这个设置,可以采用git
config命令。</span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important">$ git config --<span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">global</span> push.<span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">default</span><span style="margin:0px; padding:0px; line-height:1.5!important"> matching
# 或者
$ git config </span>--<span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">global</span> push.<span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">default</span> simple <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">(最好使用这种方式)</span></pre>
<div style="margin:0px; padding:0px"> $ git branch <span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">--track</span> master origin/master <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">//<span style="margin:0px; padding:0px; line-height:25px">在使用
git branch 命令时加上 '<span style="margin:0px; padding:0px; line-height:25px">--track<span style="margin:0px; padding:0px; line-height:25px">' 参数, 来手动创建一个追踪分支</span></span></span></span></div>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:18px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">三、常出错误:</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">1:There is no tracking information for the current branch...</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 则说明本地分?支和远程分?支的链接关系没有创建,用命令:</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> git branch --set-upstream branch-name origin/branch-name。</span><br style="margin:0px; padding:0px">
<br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">2: ![rejected] dev -> dev (non-fast-forward) ... Updates were rejected because
the tip of your current branch</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 推送失败,因为远程代码的最新提交和你试图推送的提交有冲突,解决办法也很简单,先用git pull把最新的提交从origin/dev抓下来,然后,在本地合并,解决冲突,再推送</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> </span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">3:CONFLICT (content): Merge conflict in . . .</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 这回git pull成功,但是合并有冲突,需要手动解决,解决的方法和分支管理中的解决冲突一样。解决后,提交,再push:</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> </span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">4: You are not currently on a branch, so I cannot use any</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 解决办法:git checkout master</span><br style="margin:0px; padding:0px">
<br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">5:Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 上面的显示的意思是,有一个更新还没有反应到本地来,可能是别人往server上提交了一点东西。 </span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 可以使用git pull命令拿这些更新到本地来。</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"> </p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""><span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; color:rgb(0,128,0)">6:在执行
git push 时可能会看到如下消息:</span></span></span> <br style="margin:0px; padding:0px">
</span></p>
<div class="dp-highlighter bg_html"><div class="bar"><div class="tools"><b>[html]</b> <a href="#" class="ViewSource" title="view plain" οnclick="dp.sh.Toolbar.Command('ViewSource',this);return false;" target="_blank">view plain</a><span data-mod="popu_168"> <a href="#" class="CopyToClipboard" title="copy" οnclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;" target="_blank">copy</a><div style="position: absolute; left: 486px; top: 4440px; width: 18px; height: 18px; z-index: 99;"><embed id="ZeroClipboardMovie_1" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="18" height="18" name="ZeroClipboardMovie_1" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=1&width=18&height=18" wmode="transparent"></div></span><span data-mod="popu_169"> <a href="#" class="PrintSource" title="print" οnclick="dp.sh.Toolbar.Command('PrintSource',this);return false;" target="_blank">print</a></span><a href="#" class="About" title="?" οnclick="dp.sh.Toolbar.Command('About',this);return false;" target="_blank">?</a></div></div><ol start="1" class="dp-xml"><li class="alt"><span><span class="tag"><</span><span class="tag-name">span</span><span> </span><span class="attribute">style</span><span>=</span><span class="attribute-value">"margin: 0px; padding: 0px; color: rgb(0, 128, 0);"</span><span class="tag">></span><span>warning: push.default is unset; its implicit value is changing in </span></span></li><li class=""><span>Git 2.0 from 'matching' to 'simple'. To squelch this message </span></li><li class="alt"><span>and maintain the current behavior after the default changes, use: </span></li><li class=""><span>git config --global push.default matching </span></li><li class="alt"><span>To squelch this message and adopt the new behavior now, use: </span></li><li class=""><span> git config --global push.default simpl<span class="tag"></</span><span class="tag-name">span</span><span class="tag">></span><span> </span></span></li></ol></div><pre name="code" class="html" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; display: none;"><span style="margin: 0px; padding: 0px; color: rgb(0, 128, 0);">warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simpl</span></pre>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><img src="http://images2015.cnblogs.com/blog/621032/201509/621032-20150914154420867-1000310987.png" alt="" style="margin:0px; padding:0px; border:0px; max-width:900px"></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 解决办法:‘matching’ 参数是 Git 1.x 的默认行为,如果你执行 git push 但没有指定分支,它将 push 所有你本地的分支到远程仓库中对应匹配的分支。而 Git 2.x 默认的是 simple,意味着执行 git push
没有指定分支时,只有当前分支会被 push 到你使用 git pull 获取的代码。 <br style="margin:0px; padding:0px">
根据提示,修改git push:<br style="margin:0px; padding:0px">
</span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">1</span> git config --<span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">global</span> push.<span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">default</span> matching</pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">再次执行git push 就行了。<br style="margin:0px; padding:0px">
</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"> </p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px; color:rgb(0,128,0)"><span style="margin:0px; padding:0px">7:You asked to pull from the remote 'origin', but did not specify:</span></span><span style="margin:0px; padding:0px; color:rgb(0,128,0)"><span style="margin:0px; padding:0px">a branch. Because this is not the default configured remote</span></span><span style="margin:0px; padding:0px; color:rgb(0,128,0)"><span style="margin:0px; padding:0px">for your current branch, you must specify a branch on the command line.</span></span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">解决办法:找到:</span><code style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">.git/config
修改如下</span><br style="margin:0px; padding:0px">
</code></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">1</span> [branch <span style="margin:0px; padding:0px; color:rgb(128,0,0); line-height:1.5!important">"</span><span style="margin:0px; padding:0px; color:rgb(128,0,0); line-height:1.5!important">master</span><span style="margin:0px; padding:0px; color:rgb(128,0,0); line-height:1.5!important">"</span><span style="margin:0px; padding:0px; line-height:1.5!important">]
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">2</span> remote =<span style="margin:0px; padding:0px; color:rgb(255,0,0); line-height:1.5!important"> origin
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">3</span> merge = refs/heads/master</pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"> </p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">8:ERROR: Permission
to user1/test.git denied to user2 fatal: The remote end hung up unexpectedly</span></span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 账户冲突,下面有针对讲解</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"> </p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; color:rgb(0,128,0)"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-size:15px">9: 添加的ssh不起作用?</span></span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"> ssh 的添加一定要在root用户权限在添加,其他的权限不起作用,切记!</p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:18px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">四、经验之谈:</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">1:<span style="margin:0px; padding:0px; color:rgb(0,128,0)">git revert 和 git reset的区别 </span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">开始感觉两者一样,但是在客户端和命令行窗口操作之后发现大大的不同,看一个例子:我先提交三次1,2,3 id号分别是(15d5f70,a167eb1,8fbfe3f)如下图</span><br style="margin:0px; padding:0px">
<img src="http://images.cnitblog.com/blog2015/621032/201505/072152376263370.jpg" alt="" style="margin:0px; padding:0px; border:0px; max-width:900px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">然后执行版本回退 git reset –hard a167 如图:</span><br style="margin:0px; padding:0px">
<img src="http://images.cnitblog.com/blog2015/621032/201505/072152572355512.jpg" alt="" style="margin:0px; padding:0px; border:0px; max-width:900px"></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">说明执行git reset –hard ** 版本回退是撤销某次提交,但是此次之后的修改都会被退回到暂存区,因为上面显示有提交(by 1 commit)</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">同理执行 git revert –hard a167</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">git revert是用一次新的commit来回滚之前的commit</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 在回滚操作上看,效果一样。但是在日后继续merge以前的老版本时有区别。revert是用一次逆向的commit“中和”之前的提交,</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">因此日后合并老的branch时,导致这部分改变不会再次出现,但是reset是之间把某些commit在某个branch上删除,因而和老</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">的branch再次merge时,这些被回滚的commit应该还会被引入。 </span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">得到结论:<span style="margin:0px; padding:0px; color:rgb(0,128,0)">git reset 是把HEAD向后移动了一下,而git revert是HEAD继续前进,</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">只是新的commit的内容和要revert的内容正好相反,能够抵消要被revert的内容。</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; color:rgb(0,128,0)"> 这样在版本回退的时候就比较的好,比如本地dev分支,远程master分支,某一次的上线发现线上有重大的bug,然后你reset本地代码到前一个版本,在你git push 的时候git会报一个错误:“说你的本地分支版本低于远程master分支的版本,让你先去pull
下来代码,再提交”,这就不行了,你pull下来的代码还是最新版有bug的代码,不进行pull代码,master分支又不让你提交。解决这个问题还得使用 revert 来进行 “回退”操作,为什么加引号呢,是因为这种回退是向前提交一次中和了上次的修改,这就比较好了,这样你revert之后相当于指针向前移动一次,本地版本dev高于远程master版本,这时你就可以git push 本地代码到远程了。也就是说,git reset 对未提交到(git push)远程的修改做回滚比较好,如果要回滚本地,同时想远程也回滚,就要用到revert</span><br style="margin:0px; padding:0px">
<br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:18px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">五、常用修改:</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:16px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">1:避免每次提交都输入用户名和密码</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 原因是使用了https方式 puh 在termail里边 输入 git remote -v 可以看到形如一下的返回结果</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> origin https://github.com/git/librarysystem.git(fetch)</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> origin https://github.com/git/librarysystem.git(push)</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:14px"> 下面把它换成ssh方式的。</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""><br style="margin:0px; padding:0px">
</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span>.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> git remote rm origin
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span>. git remote add origin git@github.com:yu/demo.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">git
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">3</span>. git push origin </span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:16px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">2:添加忽略文件 .gitignore </span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> .gitignore配置文件用于配置不需要加入版本管理的文件。</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 配置语法:</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> "/" 开头表示目录; </span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">"*"
通配多个字符; </span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">"?" 通配单个字符 </span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">"[]" 包含单个字符的匹配列表; </span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> "!"
表示不忽略(跟踪)匹配到的文件或目录;</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 说明:git 对于 .ignore 配置文件是按行从上到下进行规则匹配的,意味着如果前面的规则匹配的范围更大,则后面的规则将不会生效;</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 示例:</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">(1) foder/* 忽略目录foder下的全部内容,不管是根目录下的 /foder/ 目录,还是某个子目录 /list/foder/
目录,都会被忽略。</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> (2) /foder/* 说明:忽略根目录下的 /foder/ 目录的全部内容;</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> (3) /*</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">!.gitignore</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> !/fw/bin/</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> !/fw/sf/</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 说明:忽略全部内容,但是不忽略 .gitignore文件,根目录下的 /fw/bin/ 和 /fw/sf/ </span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> </span></span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""><span style="margin:0px; padding:0px; color:rgb(255,0,0)">
注意问题:</span></span><span style="margin:0px; padding:0px; color:rgb(255,0,0)"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> .gitignore文件只对还没有加入版本管理的文件起作用,如果之前已经用git把要忽略的文件纳入了版本库,就不起作用了。</span></span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:16px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; color:rgb(0,128,0)">3:如何在同一台电脑上使用两个git账户</span></span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 问题描述:作为程序员有时候是有多个的项目,而且每个项目git的用户名,邮箱等,都不一样。就我来说,我在github上有一个账号,自己开发一些东西,同时我参与的也有项目需要连接别人的github账号,在我电脑上只有一个git客户端,本地一个身份用户,开始的时候我自己开发是用ssh方式,参与的项目的是用https连接,但是https每次都需要输入密码,非常不方便,所以想转成ssh连接,利用命令:</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">>$ git remote rm origin</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">>$ git remote add origin git@github.com:yu/demo.git </span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">>$ git push origin </span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">转换成功,不幸的是push的时候出错了:<span style="margin:0px; padding:0px; color:rgb(255,0,0)">ERROR: Permission to user1 denied to</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">这种情况的解决方式是方法,使用本地托管多个个ssh的密钥,不同的账号是用不同的密匙。</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">第一步:生成SSH Key</span></span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">执行命令,如下图:</span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""><img src="http://images.cnitblog.com/blog2015/621032/201505/111126256574925.jpg" alt="" style="margin:0px; padding:0px; border:0px; max-width:900px"></span></span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">具体说明:</span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span> $ ssh-keygen -t rsa -C "your_email@youremail.com"
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span> Creates a <span style="margin:0px; padding:0px; color:rgb(0,0,255); font-size:12px!important; line-height:1.5!important">new</span> ssh <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">key</span> using the provided email Generating <span style="margin:0px; padding:0px; color:rgb(0,0,255); font-size:12px!important; line-height:1.5!important">public</span>/<span style="margin:0px; padding:0px; color:rgb(0,0,255); font-size:12px!important; line-height:1.5!important">private</span> rsa <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">key</span> pair.
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">3</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">#</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">输入将要保存的路径,我的默认为当前路径(/c/Users/zhaoyafei/.ssh/id_rsa),但是不能使用默认文件id_rsa,要添加新账户就要生起一个成新的好记的名字,例如id_rsa_work</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">4</span> Enter <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">file</span> in which to save the <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">key</span> (/c/Users/zhaoyafei/.ssh/id_rsa):
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">5</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">#</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">输入回车后提示输入一个类似于密码的号,直接回车就行</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">6</span> Enter passphrase (<span style="margin:0px; padding:0px; color:rgb(0,0,255); font-size:12px!important; line-height:1.5!important">empty</span> <span style="margin:0px; padding:0px; color:rgb(0,0,255); font-size:12px!important; line-height:1.5!important">for</span> no passphrase):
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">7</span> Enter same passphrase again:</span></pre>
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-size:16px; font-family:"Microsoft YaHei"">第二步:识别新的私钥</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"> <span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 默认SSH只会读取id_rsa,所以为了让SSH识别新的私钥,需要将其添加到SSH agent </span> </span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span> ssh-add ~/.ssh/<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">id_rsa_work
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">//</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">该命令如果报错:Could not open a connection to your authentication agent.可执行 ssh-agent bash 命令后再执行ssh-add -l 看是否成功。</span></span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">执行命令,如下图:</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><img src="http://images.cnitblog.com/blog2015/621032/201505/111127561579343.jpg" alt="" style="margin:0px; padding:0px; border:0px; max-width:900px"></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"> </p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-size:16px; font-family:"Microsoft YaHei"">第三步:修改config文件</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 该文件用于配置私钥对应的服务器。内容如下:</span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:14px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 1</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">#</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important"> Default github (默认的)</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 2</span> Host github.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">com
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 3</span> HostName github.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">com
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 4</span> <span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> User git
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 5</span> IdentityFile ~/.ssh/<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">id_rsa
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 6</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 7</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">#</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important"> second user(work@gmail.com)</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 8</span> <span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> Host github_work
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 9</span> HostName github.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">com
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">10</span> <span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> User git
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">11</span> IdentityFile ~/.ssh/id_rsa_work</span></pre>
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"> <span style="margin:0px; padding:0px; font-size:15px; font-family:"Microsoft YaHei""> 这样配置,也就是使用hostname为github.com会根据用户名的不同,去使用不用的private key。github上,也可以添加对应的公钥。其实这个配置是关于ssh的与git无关,只是git使用的方式是ssh的方式。Host可随意,方便自己记忆,后续在添加remote是还需要用到。</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-size:15px; font-family:"Microsoft YaHei"">第四步:将SSH key输入到GitHub网站中</span></span> <br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:15px; font-family:"Microsoft YaHei"">将生成的id_rsa_work.pub输入到GitHub网站中就可以了,输入完成后单击Add key后,会看到git-tutorial已经被添加进去了。 配置完成后,在连接非默认帐号的github仓库时,远程库的地址要对应地做一些修改,比如现在添加abc帐号下的一个仓库test,则需要这样添加:<span style="margin:0px; padding:0px; color:rgb(0,128,0)">git
remote add test git@github-work:abc/test.git #并非原来的git@github.com:abc/test.git</span> 这样每次连接都会使用id_rsa_abc与服务器进行连接。</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px"><span style="margin:0px; padding:0px; color:rgb(255,0,0)"> <span style="margin:0px; padding:0px">注意:</span></span>github根据配置文件的user.email来获取github帐号显示author信息,所以对于多帐号用户一定要记得将user.email改为相应的email(work@mail.com)。我遇到的问题是本地单一用户,链接不同的github账号,所以用户配置可以采用全局配置。如果不同本地用户(不同的身份标识,即需要本地使用不同的用户名),那么git就不要使用有–global的配置,可以按照下面的方法:</span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:14px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span> 1)设置局部的user.name和user.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">email
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span> git config user.name "xxxxxx"
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">3</span> git config user.email "xxx@xxx.com"
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">4</span> 2)设置全局的user.name和user.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">email
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">5</span> git config --global user.name "xxxxxx"
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">6</span> git config –-<span style="margin:0px; padding:0px; line-height:1.5!important">global</span> user.email ""</span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:18px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">六、题外话(相关概念)</span></span></span></p>
<p style="margin:10px auto 10px 30px; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">Git - 版本控制工具</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> Git是一个开源的分布式版本控制系统,用以有效、高速的处理从很小到非常大的项目版本管理。</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">Git 是 Linus Torvalds 为了帮助管理
Linux 内核开发而开发的一个开放源码的版本控制软件。</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">Torvalds 开始着手开发 Git 是为了作为一种过渡方案来替代 BitKeeper,后者之前一直是 Linux 内核开发人员在全球使用的主要源代码工具。开放源码社区中的有些人觉得 BitKeeper 的许可证并不适合开放源码社区的工作,因此 Torvalds 决定着手研究许可证更为灵活的版本控制系统。尽管最初
Git 的开发是为了辅助 Linux 内核开发的过程,但是我们已经发现在很多其他自由软件项目中也使用了 Git。例如 最近就迁移到 Git 上来了,很多 Freedesktop 的项目也迁移到了 Git 上。</span></span></p>
<p style="margin:10px auto 10px 30px; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">Github - 一个网站,提供给用户空间创建git仓储,保存用户的一些数据文档或者代码等</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 作为开源代码库以及版本控制系统,Github目前拥有140多万开发者用户。随着越来越多的应用程序转移到了云上,Github已经成为了管理软件开发以及发现已有代码的首选方法。</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">如前所述,作为一个分布式的版本控制系统,在Git中并不存在主库这样的概念,每一份复制出的库都可以独立使用,任何两个库之间的不一致之处都可以进行合并。</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">GitHub可以托管各种git库,并提供一个web界面,但与其它像
SourceForge或Google Code这样的服务不同,GitHub的独特卖点在于从另外一个项目进行分支的简易性。为一个项目贡献代码非常简单:首先点击项目站点的“fork”的按 钮,然后将代码检出并将修改加入到刚才分出的代码库中,最后通过内建的“pull request”机制向项目负责人申请代码合并。已经有人将GitHub称为代码玩家的MySpace。</span></span></p>
<p style="margin:10px auto 10px 30px; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">GitLab - 基于Git的项目管理软件</span></span><br style="margin:0px; padding:0px">
</p>
<p><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">GitLab 是一个用于仓库管理系统的开源项目。使用Git作为代码管理工具,并在此基础上搭建起来的web服务。三者都是基于git的,可以说是git的衍生品。</span></p>
<p><span style="font-family:Microsoft YaHei">文章出处:http://www.cnblogs.com/zyf-zhaoyafei/p/4486220.html</span></p>
</div>
</div>
</div>
<!-- Baidu Button BEGIN -->
<div class="bdsharebuttonbox tracking-ad bdshare-button-style0-16" style="float: right;" data-mod="popu_172" data-bd-bind="1505991722359">
<a href="#" class="bds_more" data-cmd="more" style="background-position:0 0 !important; background-image: url(http://bdimg.share.baidu.com/static/api/img/share/icons_0_16.png?v=d754dcc0.png) !important" target="_blank"></a>
<a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间" style="background-position:0 -52px !important" target="_blank"></a>
<a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博" style="background-position:0 -104px !important" target="_blank"></a>
<a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博" style="background-position:0 -260px !important" target="_blank"></a>
<a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网" style="background-position:0 -208px !important" target="_blank"></a>
<a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信" style="background-position:0 -1612px !important" target="_blank"></a>
</div>
<script>window._bd_share_config = { "common": { "bdSnsKey": {}, "bdText": "", "bdMini": "1", "bdMiniList": false, "bdPic": "", "bdStyle": "0", "bdSize": "16" }, "share": {} }; with (document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];</script>
<!-- Baidu Button END -->
<!--172.16.140.11-->
<!-- Baidu Button BEGIN -->
<script type="text/javascript" id="bdshare_js" data="type=tools&uid=1536434" src="http://bdimg.share.baidu.com/static/js/bds_s_v2.js?cdnversion=418332"></script>
<script type="text/javascript">
document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil(new Date()/3600000)
</script>
<!-- Baidu Button END -->
<div id="digg" articleid="74078228">
<dl id="btnDigg" class="digg digg_enable" οnclick="btndigga();">
<dt>顶</dt>
<dd>0</dd>
</dl>
<dl id="btnBury" class="digg digg_enable" οnclick="btnburya();">
<dt>踩</dt>
<dd>0</dd>
</dl>
</div>
<div class="tracking-ad" data-mod="popu_222"><a href="javascript:void(0);" target="_blank"> </a> </div>
<div class="tracking-ad" data-mod="popu_223"> <a href="javascript:void(0);" target="_blank"> </a></div>
<script type="text/javascript">
function btndigga() {
$(".tracking-ad[data-mod='popu_222'] a").click();
}
function btnburya() {
$(".tracking-ad[data-mod='popu_223'] a").click();
}
</script>
<ul class="article_next_prev">
<li class="prev_article"><span οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_shangyipian']);location.href='http://blog.csdn.net/sunayxin/article/details/74078159';">上一篇</span><a href="http://blog.csdn.net/sunayxin/article/details/74078159" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_shangyipian'])">经典的排序算法</a></li>
<li class="next_article"><span οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_xiayipian']);location.href='http://blog.csdn.net/sunayxin/article/details/74079978';">下一篇</span><a href="http://blog.csdn.net/sunayxin/article/details/74079978" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_xiayipian'])">网站第三方登录(php版)</a></li>
</ul>
<div style="clear:both; height:10px;"></div>
<div class="similar_article">
<h4></h4>
<div class="similar_c" style="margin:20px 0px 0px 0px">
<div class="similar_c_t">
相关文章推荐
</div>
<div class="similar_wrap tracking-ad" data-mod="popu_36" style="max-height:250px">
<ul class="similar_list fl">
<li>
<em>•</em>
<a href="http://download.csdn.net/download/doris_d/8494441" title="git学习总结" strategy="BlogCommendFromCsdn_0" target="_blank">git学习总结</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/huiyiCourse/series_detail/64?utm_source=blog7" title="大数据技术实战线上峰会--董西成" strategy="undefined" target="_blank">大数据技术实战线上峰会--董西成</a>
</li>
<li>
<em>•</em>
<a href="http://download.csdn.net/download/wsh19930305/9688055" title="git命令学习总结" strategy="BlogCommendFromCsdn_1" target="_blank">git命令学习总结</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/huiyiCourse/series_detail/61?utm_source=blog7" title="30天系统掌握机器学习--唐宇迪" strategy="undefined" target="_blank">30天系统掌握机器学习--唐宇迪</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/ApplyDev/article/details/52824305" title="Git学习总结" strategy="BlogCommendFromCsdn_2" target="_blank">Git学习总结</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/combo/detail/382?utm_source=blog7" title="ORACLE数据库学习资料集锦" strategy="undefined" target="_blank">ORACLE数据库学习资料集锦</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/shi_weihappy/article/details/42471115" title="Git命令学习总结(-)" strategy="BlogCommendFromCsdn_3" target="_blank">Git命令学习总结(-)</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/course/detail/3010?utm_source=blog7" title="PHP从零开始实战篇" strategy="undefined" target="_blank">PHP从零开始实战篇</a>
</li>
</ul>
<ul class="similar_list fr">
<li>
<em>•</em>
<a href="http://blog.csdn.net/yanxiangyfg/article/details/49947635" title="git学习--gerrit服务器搭建总结" strategy="BlogCommendFromCsdn_4" target="_blank">git学习--gerrit服务器搭建总结</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/course/detail/3149?utm_source=blog7" title="玩转微信小程序第一篇" strategy="undefined" target="_blank">玩转微信小程序第一篇</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/doris_d/article/details/42869363" title="git学习总结" strategy="BlogCommendFromCsdn_5" target="_blank">git学习总结</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/course/detail/4565?utm_source=blog7" title="深度学习案例分享—人脸检测" strategy="undefined" target="_blank">深度学习案例分享—人脸检测</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/weixin_38021928/article/details/70186036" title="Java 版本控制工具-Git 学习总结" strategy="BlogCommendFromCsdn_6" target="_blank">Java 版本控制工具-Git 学习总结</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/tanghua0809/article/details/45726399" title="Android 开发git学习,常用命令总结" strategy="BlogCommendFromCsdn_7" target="_blank">Android 开发git学习,常用命令总结</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/wayne566/article/details/75591901" title="Git入门基本操作学习总结(更新中)" strategy="BlogCommendFromCsdn_8" target="_blank">Git入门基本操作学习总结(更新中)</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/shi923281339/article/details/62425321" title="Git学习总结(一):本地操作" strategy="BlogCommendFromCsdn_9" target="_blank">Git学习总结(一):本地操作</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="article_title">
<span class="ico ico_type_Repost"></span>
<h1>
<span class="link_title"><a href="/sunayxin/article/details/74078228">
GIT学习总结
</a>
</span>
</h1>
</div>
<div class="article_manage clearfix">
<div class="article_r">
<span class="link_postdate">2017-07-01 18:24</span>
<span class="link_view" title="阅读次数">39人阅读</span>
<span class="link_comments" title="评论次数"> <a href="#comments" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_pinglun'])">评论</a>(0)</span>
<span class="link_collect tracking-ad" data-mod="popu_171"> <a href="javascript:void(0);" οnclick="javascript:collectArticle('GIT%e5%ad%a6%e4%b9%a0%e6%80%bb%e7%bb%93','74078228');return false;" title="收藏" target="_blank">收藏</a></span>
<span class="link_report"> <a href="#report" οnclick="javascript:report(74078228,2);return false;" title="举报">举报</a></span>
</div>
</div> <style type="text/css">
.embody{
padding:10px 10px 10px;
margin:0 -20px;
border-bottom:solid 1px #ededed;
}
.embody_b{
margin:0 ;
padding:10px 0;
}
.embody .embody_t,.embody .embody_c{
display: inline-block;
margin-right:10px;
}
.embody_t{
font-size: 12px;
color:#999;
}
.embody_c{
font-size: 12px;
}
.embody_c img,.embody_c em{
display: inline-block;
vertical-align: middle;
}
.embody_c img{
width:30px;
height:30px;
}
.embody_c em{
margin: 0 20px 0 10px;
color:#333;
font-style: normal;
}
</style>
<script type="text/javascript">
$(function () {
try
{
var lib = eval("("+$("#lib").attr("value")+")");
var html = "";
if (lib.err == 0) {
$.each(lib.data, function (i) {
var obj = lib.data[i];
//html += '<img src="' + obj.logo + '"/>' + obj.name + " ";
html += ' <a href="' + obj.url + '" target="_blank">';
html += ' <img src="' + obj.logo + '">';
html += ' <em><b>' + obj.name + '</b></em>';
html += ' </a>';
});
if (html != "") {
setTimeout(function () {
$("#lib").html(html);
$("#embody").show();
}, 100);
}
}
} catch (err)
{ }
});
</script>
<div class="category clearfix">
<div class="category_l">
<img src="http://static.blog.csdn.net/images/category_icon.jpg">
<span>分类:</span>
</div>
<div class="category_r">
<label>
<span οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_fenlei']);">GIT<em></em></span>
</label>
</div>
</div>
<div id="article_content" class="article_content tracking-ad" data-mod="popu_307" data-dsm="post">
<h1 class="postTitle" style="margin:0px; padding:0px; position:relative; width:760px; border:none; font-family:微软雅黑">
<a target="_blank" id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/zyf-zhaoyafei/p/4486220.html" style="margin:0px; padding:0px; color:rgb(106,99,82); font-family:微软雅黑,华文细黑,黑体,Arial; font-size:18px; font-weight:normal">git学习总结</a></h1>
<div class="clear" style="margin:0px; padding:0px; clear:both; font-family:微软雅黑">
</div>
<div class="postBody" style="margin:10px 0px 0px; padding:0px; position:relative; width:760px; height:auto; border:none; color:rgb(73,73,73); font-size:14px; line-height:1.6">
<div id="cnblogs_post_body" style="margin:0px 0px 20px; padding:0px; background-color:transparent; word-break:break-word">
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px">git remote rename github gh</p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">最近学习学习git,总结了一点关于git的使用命令和遇到的问题</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">众所周知,Git是目前世界上最先进的分布式版本控制系统。下面说下git的使用知识</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:18px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">一、SVN与Git的最主要的区别?</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px"> <span style="margin:0px; padding:0px; font-size:14px"> 说起git自然想到<span style="margin:0px; padding:0px; color:rgb(0,128,0)">SVN</span>,我刚接触到的版本控制工具是SVN,<span style="margin:0px; padding:0px; color:rgb(0,128,0)">SVN是集中式版本控制系统,版本库是集中放在中央服务器的</span>,干活的时候,先要从中央服务器哪里得到最新的版本,干完活后,需要把自己做完的活推送到中央服务器。中央服务器就好比是一个图库,你要改一本书,必须先从图库借出来,然后回到家自己改,改完了,再放回图库。集中式版本控制系统是必须联网才能工作,如果在局域网还可以,带宽够大,速度够快,如果在互联网下,如果网速慢的话,就耽误事了。</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> Git是分布式版本控制系统,它没有中央服务器的,<span style="margin:0px; padding:0px; color:rgb(0,128,0)">每个人的电脑就是一个完整的版本库,</span>工作的时候就不需要联网了,因为版本都是在自己的电脑上。既然每个人的电脑都有一个完整的版本库,那多个人如何协作呢?比如说自己在电脑上改了文件A,其他人也在电脑上改了文件A,这时,你们两之间只需把各自的修改推送给对方,就可以互相看到对方的修改了。</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 和集中式版本控制系统相比,分布式版本控制系统的安全性要高很多,因为每个人电脑里都有完整的版本库,某一个人的电脑坏掉了不要紧,随便从其他人那里复制一个就可以了。而集中式版本控制系统的中央服务器要是出了问题,所有人都没法干活了。</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">Git基本常用命令如下:</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:18px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">二、常用的git命令</span></span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">--文件目录操作命令</span></span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span> <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">mkdir</span> **: 创建一个空目录 **<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">指目录名
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span> <span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">pwd: 显示当前目录的路径。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">3</span> cat ** 查看**<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">文件内容
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">4</span> git rm ** 删除**文件</span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">--git初始化操作</span></span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span> git init 把当前的目录变成可以管理的git仓库,生成隐藏.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">git文件。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span> git remote add origin https:<span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">//</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">github.com/git/librarysystem.git 把本地仓库的内容推送到GitHub仓库。</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">3</span> git <span style="margin:0px; padding:0px; color:rgb(0,0,255); font-size:12px!important; line-height:1.5!important">clone</span> git@github.com:michaelliao/gitskills.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">git 从远程库克隆
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">4</span> git add **<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> 把xx文件添加到暂存区去。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">5</span> git commit –m "**" 提交文件 –m 后面的是注释。</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:14px; line-height:1.5!important"><span style="margin:0px; padding:0px; font-family:"Courier New"!important; font-size:13px; line-height:1.5!important"> </span> </span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">--git 克隆分支</span></span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">1</span> git <span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">clone</span> xxx.git <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">//</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">最简单直接的命令</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">2</span> git <span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">clone</span> xxx.git "指定目录" <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">//</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">clone到指定目录</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">3</span> git <span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">clone</span> -b [new_branch_name] xxx.git <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">//</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">clone时创建新的分支替代默认Origin HEAD(master)</span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px; line-height:19px; color:rgb(75,75,75); font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; line-height:18px; font-family:"Microsoft YaHei"; font-size:15px; color:rgb(0,0,0)">--clone 远程分支</span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px; line-height:19px; color:rgb(75,75,75); font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="margin:0px; padding:0px; line-height:18px; font-family:"Microsoft YaHei"; font-size:14px; color:rgb(0,0,0)"> <span style="margin:0px; padding:0px">git clone 命令默认的只会建立master分支</span>,如果你想clone指定的某一远程分支(如:dev)的话,可以如下:</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px; line-height:19px; color:rgb(75,75,75); font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="margin:0px; padding:0px; line-height:18px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:14px; color:rgb(0,0,0)"> 1. 查看所有分支(包括隐藏的) </span><span style="margin:0px; padding:0px; line-height:19px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:14px; color:rgb(0,0,0)">git
branch -a 显示所有分支</span><span style="margin:0px; padding:0px; line-height:18px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:14px; color:rgb(0,0,0)"> </span> </span></span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">1</span> *<span style="margin:0px; padding:0px; line-height:1.5!important"> master
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">2</span> remotes/origin/HEAD -> origin/<span style="margin:0px; padding:0px; line-height:1.5!important">master
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">3</span> remotes/origin/<span style="margin:0px; padding:0px; line-height:1.5!important">dev
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">4</span> remotes/origin/master</pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px; line-height:19px; color:rgb(75,75,75); font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:14px; color:rgb(0,0,0)"> 2. <span style="margin:0px; padding:0px">在本地新建同名的("dev")分支,并切换到该分支</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">1</span> git checkout -t origin/<span style="margin:0px; padding:0px; line-height:1.5!important">dev 该命令等同于:
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">2</span> git checkout -b dev origin/dev</pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px">--查看命令</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span> <span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">git status 查看仓库状态
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span> git diff **<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> 查看XX文件修改了那些内容
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">3</span> git <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">log</span><span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> 查看历史记录
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">4</span> git reflog 查看历史记录的版本号id(记录你的每一次命令,<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">不论是否提交)
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">5</span> git <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">log</span> --pretty=oneline 如果信息量太多可以进行比较好的列表显示</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:14px; line-height:1.5!important"><span style="margin:0px; padding:0px; font-family:"Courier New"!important; font-size:13px; line-height:1.5!important"> </span> </span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px">--版本回退</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span> git <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">reset</span> –hard HEAD^ 或者 git <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">reset</span> --hard HEAD~<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> 回退到上一个版本
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span> (如果想回退到80个版本,使用git <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">reset</span> –hard HEAD~80 git <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">reset</span> --hard 版本号)</span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px">--撤销修改</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 1</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">checkout
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 2</span> <span style="margin:0px; padding:0px; line-height:1.5!important">恢复某个已修改的文件(撤销未提交的修改):
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 3</span> $ <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git checkout file-name
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 4</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 5</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">revert
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 6</span> <span style="margin:0px; padding:0px; line-height:1.5!important">还原已提交的修改(已经提交过的修改)
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 7</span> <span style="margin:0px; padding:0px; line-height:1.5!important">还原最近一次提交的修改:
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 8</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,0,0); line-height:1.5!important">$</span> git revert HEAD
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 9</span> <span style="margin:0px; padding:0px; line-height:1.5!important">还原指定版本的修改:
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">10</span> $ <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git revert commit-id</span></pre>
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px">--分支管理</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important">git push –u(第一次要用-<span style="margin:0px; padding:0px; line-height:1.5!important">u 以后不需要) origin master 把当前master分支推送到远程库
git branch 查看本地所有的分支<br style="margin:0px; padding:0px">git branch -a 查看远程<span style="margin:0px; padding:0px; line-height:1.5!important">所有的</span>分支
git branch name 创建分支<br style="margin:0px; padding:0px">
git checkout — </span>**<span style="margin:0px; padding:0px; line-height:1.5!important"> 把XX文件在工作区的修改全部撤销。
git checkout –b dev 创建dev分支 并切换到dev分支上
git checkout master 切换回master分支<br style="margin:0px; padding:0px">
git branch –d dev 删除dev分支
git merge dev 在当前的分支上合并dev分支
git push </span>--<span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">set</span>-<span style="margin:0px; padding:0px; line-height:1.5!important">upstream origin dev 提交修改并创建远程分支dev
git push origin zyf</span>-dev 把当前的分支 zyf-dev 推送到远程(远程仓库没有给分支则会新建立该分支)<br style="margin:0px; padding:0px"><br style="margin:0px; padding:0px">git merge dev 在当前分支上合并dev分支代</pre>
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px">--隐藏的文件</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span> <span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">git stash 把当前的工作隐藏起来 等以后恢复现场后继续工作
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span> git stash <span style="margin:0px; padding:0px; color:rgb(0,0,255); font-size:12px!important; line-height:1.5!important">list</span><span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> 查看所有被隐藏的文件列表
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">3</span> <span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">git stash apply 恢复被隐藏的文件,但是内容不删除
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">4</span> <span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">git stash drop 删除文件
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">5</span> git stash pop 恢复文件的同时 也删除文件</span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px">--查看远程库信息(git remote的用法)</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""><span style="margin:0px; padding:0px; font-size:15px"> </span></span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; font-family:"Courier New"!important; font-size:12px!important; line-height:1.5!important; color:rgb(0,128,0)">1</span> git remote 查看远程库的信息
<span style="margin:0px; padding:0px; font-family:"Courier New"!important; font-size:12px!important; line-height:1.5!important; color:rgb(0,128,0)">2</span> git remote –v 查看远程库的详细信息</span><br style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:14px; line-height:1.5!important"><span style="margin:0px; padding:0px; font-family:"Courier New"!important; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">3</span> git remote add name url 添加远程仓库<br style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">4</span> git remote rename oldname newname 重命名仓库<br style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">5</span> git remote rm 删除仓库<code style="margin:0px; padding:0px"></code></span><br style="margin:0px; padding:0px"></span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px">--将远程分支拉取到本地<span style="margin:0px; padding:0px; font-size:14px"><span style="margin:0px; padding:0px; font-size:15px"><br style="margin:0px; padding:0px">
</span></span></span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">1</span> 方法一:<span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git checkout -b 本地分支名x origin/远程分支名x
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">2</span> 方式二:<span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git fetch origin 远程分支名x:本地分支名x</span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-size:15px">--git pull操作</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 1</span> <span style="margin:0px; padding:0px; line-height:1.5!important">git pull命令的作用是,取回远程主机某个分支的更新,再与本地的指定分支合并,基本的格式如下。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 2</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">$ git pull <远程主机名> <远程分支名>:<本地分支名></span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 3</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 4</span> <span style="margin:0px; padding:0px; line-height:1.5!important">取回origin主机的next分支,与本地的master分支合并,需要写成下面这样
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 5</span> <span style="margin:0px; padding:0px; line-height:1.5!important">$ <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git pull origin next:master
</span></span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 6</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 7</span> <span style="margin:0px; padding:0px; line-height:1.5!important">如果远程分支是与当前分支合并,则冒号后面的部分可以省略。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 8</span> <span style="margin:0px; padding:0px; line-height:1.5!important">$ <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git pull origin next
</span></span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important"> 9</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">10</span> 上面命令表示,取回origin/<span style="margin:0px; padding:0px; line-height:1.5!important">next分支,再与当前分支合并。实质上,这等同于先做git fetch,再做git merge。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">11</span> <span style="margin:0px; padding:0px; line-height:1.5!important">$ <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git fetch origin
</span></span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">12</span> $ <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git merge origin/next
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">13</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">14</span> 在某些场合,Git会自动在本地分支与远程分支之间,建立一种追踪关系(tracking)。比如,在git clone的时候,所有本地分支默认与远程主机的同名分支,建立追踪关系,也就是说,本地的master分支自动”追踪”origin/<span style="margin:0px; padding:0px; line-height:1.5!important">master分支。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">15</span> <span style="margin:0px; padding:0px; line-height:1.5!important">Git也允许手动建立追踪关系。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">16</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git branch --set-upstream master origin/next
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">17</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">18</span> 上面命令指定master分支追踪origin/<span style="margin:0px; padding:0px; line-height:1.5!important">next分支。如果当前分支与远程分支存在追踪关系,git pull就可以省略远程分支名。
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">19</span> $ <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">git pull origin</span></pre>
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-size:15px; font-family:"Microsoft YaHei"">--git 设置大小写敏感</span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px">Windows上的Git默认是大小写不敏感的,这样多平台写作就可能会出现问题。Win上的Git设置为大小写敏感的命令如下</p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">1</span> git config core.ignorecase <span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">false</span> </pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-size:15px; font-family:"Microsoft YaHei"">--git 设置忽略文件或文件夹权限修改</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">1</span> git config core.filemode <span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">false</span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-size:15px; font-family:"Microsoft YaHei""><span style="margin:0px; padding:0px">--创建追踪分支</span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; color:rgb(0,0,0)">不带任何参数的git push,默认只推送当前分支,这叫做simple方式。此外,还有一种matching方式,会推送所有有对应的远程分支的本地分支。Git 2.0版本之前,默认采用matching方法,现在改为默认采用simple方式。如果要修改这个设置,可以采用git
config命令。</span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important">$ git config --<span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">global</span> push.<span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">default</span><span style="margin:0px; padding:0px; line-height:1.5!important"> matching
# 或者
$ git config </span>--<span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">global</span> push.<span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">default</span> simple <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">(最好使用这种方式)</span></pre>
<div style="margin:0px; padding:0px"> $ git branch <span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">--track</span> master origin/master <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">//<span style="margin:0px; padding:0px; line-height:25px">在使用
git branch 命令时加上 '<span style="margin:0px; padding:0px; line-height:25px">--track<span style="margin:0px; padding:0px; line-height:25px">' 参数, 来手动创建一个追踪分支</span></span></span></span></div>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:18px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">三、常出错误:</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">1:There is no tracking information for the current branch...</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 则说明本地分?支和远程分?支的链接关系没有创建,用命令:</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> git branch --set-upstream branch-name origin/branch-name。</span><br style="margin:0px; padding:0px">
<br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">2: ![rejected] dev -> dev (non-fast-forward) ... Updates were rejected because
the tip of your current branch</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 推送失败,因为远程代码的最新提交和你试图推送的提交有冲突,解决办法也很简单,先用git pull把最新的提交从origin/dev抓下来,然后,在本地合并,解决冲突,再推送</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> </span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">3:CONFLICT (content): Merge conflict in . . .</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 这回git pull成功,但是合并有冲突,需要手动解决,解决的方法和分支管理中的解决冲突一样。解决后,提交,再push:</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> </span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">4: You are not currently on a branch, so I cannot use any</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 解决办法:git checkout master</span><br style="margin:0px; padding:0px">
<br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">5:Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 上面的显示的意思是,有一个更新还没有反应到本地来,可能是别人往server上提交了一点东西。 </span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 可以使用git pull命令拿这些更新到本地来。</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"> </p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""><span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; color:rgb(0,128,0)">6:在执行
git push 时可能会看到如下消息:</span></span></span> <br style="margin:0px; padding:0px">
</span></p>
<div class="dp-highlighter bg_html"><div class="bar"><div class="tools"><b>[html]</b> <a href="#" class="ViewSource" title="view plain" οnclick="dp.sh.Toolbar.Command('ViewSource',this);return false;" target="_blank">view plain</a><span data-mod="popu_168"> <a href="#" class="CopyToClipboard" title="copy" οnclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;" target="_blank">copy</a><div style="position: absolute; left: 486px; top: 4440px; width: 18px; height: 18px; z-index: 99;"><embed id="ZeroClipboardMovie_1" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="18" height="18" name="ZeroClipboardMovie_1" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=1&width=18&height=18" wmode="transparent"></div></span><span data-mod="popu_169"> <a href="#" class="PrintSource" title="print" οnclick="dp.sh.Toolbar.Command('PrintSource',this);return false;" target="_blank">print</a></span><a href="#" class="About" title="?" οnclick="dp.sh.Toolbar.Command('About',this);return false;" target="_blank">?</a></div></div><ol start="1" class="dp-xml"><li class="alt"><span><span class="tag"><</span><span class="tag-name">span</span><span> </span><span class="attribute">style</span><span>=</span><span class="attribute-value">"margin: 0px; padding: 0px; color: rgb(0, 128, 0);"</span><span class="tag">></span><span>warning: push.default is unset; its implicit value is changing in </span></span></li><li class=""><span>Git 2.0 from 'matching' to 'simple'. To squelch this message </span></li><li class="alt"><span>and maintain the current behavior after the default changes, use: </span></li><li class=""><span>git config --global push.default matching </span></li><li class="alt"><span>To squelch this message and adopt the new behavior now, use: </span></li><li class=""><span> git config --global push.default simpl<span class="tag"></</span><span class="tag-name">span</span><span class="tag">></span><span> </span></span></li></ol></div><pre name="code" class="html" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; display: none;"><span style="margin: 0px; padding: 0px; color: rgb(0, 128, 0);">warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simpl</span></pre>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><img src="http://images2015.cnblogs.com/blog/621032/201509/621032-20150914154420867-1000310987.png" alt="" style="margin:0px; padding:0px; border:0px; max-width:900px"></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 解决办法:‘matching’ 参数是 Git 1.x 的默认行为,如果你执行 git push 但没有指定分支,它将 push 所有你本地的分支到远程仓库中对应匹配的分支。而 Git 2.x 默认的是 simple,意味着执行 git push
没有指定分支时,只有当前分支会被 push 到你使用 git pull 获取的代码。 <br style="margin:0px; padding:0px">
根据提示,修改git push:<br style="margin:0px; padding:0px">
</span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">1</span> git config --<span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">global</span> push.<span style="margin:0px; padding:0px; color:rgb(0,0,255); line-height:1.5!important">default</span> matching</pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">再次执行git push 就行了。<br style="margin:0px; padding:0px">
</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"> </p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px; color:rgb(0,128,0)"><span style="margin:0px; padding:0px">7:You asked to pull from the remote 'origin', but did not specify:</span></span><span style="margin:0px; padding:0px; color:rgb(0,128,0)"><span style="margin:0px; padding:0px">a branch. Because this is not the default configured remote</span></span><span style="margin:0px; padding:0px; color:rgb(0,128,0)"><span style="margin:0px; padding:0px">for your current branch, you must specify a branch on the command line.</span></span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">解决办法:找到:</span><code style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">.git/config
修改如下</span><br style="margin:0px; padding:0px">
</code></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">1</span> [branch <span style="margin:0px; padding:0px; color:rgb(128,0,0); line-height:1.5!important">"</span><span style="margin:0px; padding:0px; color:rgb(128,0,0); line-height:1.5!important">master</span><span style="margin:0px; padding:0px; color:rgb(128,0,0); line-height:1.5!important">"</span><span style="margin:0px; padding:0px; line-height:1.5!important">]
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">2</span> remote =<span style="margin:0px; padding:0px; color:rgb(255,0,0); line-height:1.5!important"> origin
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">3</span> merge = refs/heads/master</pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"> </p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">8:ERROR: Permission
to user1/test.git denied to user2 fatal: The remote end hung up unexpectedly</span></span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 账户冲突,下面有针对讲解</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"> </p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; color:rgb(0,128,0)"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-size:15px">9: 添加的ssh不起作用?</span></span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"> ssh 的添加一定要在root用户权限在添加,其他的权限不起作用,切记!</p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:18px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">四、经验之谈:</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">1:<span style="margin:0px; padding:0px; color:rgb(0,128,0)">git revert 和 git reset的区别 </span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">开始感觉两者一样,但是在客户端和命令行窗口操作之后发现大大的不同,看一个例子:我先提交三次1,2,3 id号分别是(15d5f70,a167eb1,8fbfe3f)如下图</span><br style="margin:0px; padding:0px">
<img src="http://images.cnitblog.com/blog2015/621032/201505/072152376263370.jpg" alt="" style="margin:0px; padding:0px; border:0px; max-width:900px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">然后执行版本回退 git reset –hard a167 如图:</span><br style="margin:0px; padding:0px">
<img src="http://images.cnitblog.com/blog2015/621032/201505/072152572355512.jpg" alt="" style="margin:0px; padding:0px; border:0px; max-width:900px"></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">说明执行git reset –hard ** 版本回退是撤销某次提交,但是此次之后的修改都会被退回到暂存区,因为上面显示有提交(by 1 commit)</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">同理执行 git revert –hard a167</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">git revert是用一次新的commit来回滚之前的commit</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 在回滚操作上看,效果一样。但是在日后继续merge以前的老版本时有区别。revert是用一次逆向的commit“中和”之前的提交,</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">因此日后合并老的branch时,导致这部分改变不会再次出现,但是reset是之间把某些commit在某个branch上删除,因而和老</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">的branch再次merge时,这些被回滚的commit应该还会被引入。 </span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">得到结论:<span style="margin:0px; padding:0px; color:rgb(0,128,0)">git reset 是把HEAD向后移动了一下,而git revert是HEAD继续前进,</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">只是新的commit的内容和要revert的内容正好相反,能够抵消要被revert的内容。</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; color:rgb(0,128,0)"> 这样在版本回退的时候就比较的好,比如本地dev分支,远程master分支,某一次的上线发现线上有重大的bug,然后你reset本地代码到前一个版本,在你git push 的时候git会报一个错误:“说你的本地分支版本低于远程master分支的版本,让你先去pull
下来代码,再提交”,这就不行了,你pull下来的代码还是最新版有bug的代码,不进行pull代码,master分支又不让你提交。解决这个问题还得使用 revert 来进行 “回退”操作,为什么加引号呢,是因为这种回退是向前提交一次中和了上次的修改,这就比较好了,这样你revert之后相当于指针向前移动一次,本地版本dev高于远程master版本,这时你就可以git push 本地代码到远程了。也就是说,git reset 对未提交到(git push)远程的修改做回滚比较好,如果要回滚本地,同时想远程也回滚,就要用到revert</span><br style="margin:0px; padding:0px">
<br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:18px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">五、常用修改:</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:16px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">1:避免每次提交都输入用户名和密码</span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 原因是使用了https方式 puh 在termail里边 输入 git remote -v 可以看到形如一下的返回结果</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> origin https://github.com/git/librarysystem.git(fetch)</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> origin https://github.com/git/librarysystem.git(push)</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:14px"> 下面把它换成ssh方式的。</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""><br style="margin:0px; padding:0px">
</span></span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span>.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> git remote rm origin
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span>. git remote add origin git@github.com:yu/demo.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">git
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">3</span>. git push origin </span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:16px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">2:添加忽略文件 .gitignore </span></span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> .gitignore配置文件用于配置不需要加入版本管理的文件。</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 配置语法:</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> "/" 开头表示目录; </span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">"*"
通配多个字符; </span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">"?" 通配单个字符 </span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">"[]" 包含单个字符的匹配列表; </span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> "!"
表示不忽略(跟踪)匹配到的文件或目录;</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 说明:git 对于 .ignore 配置文件是按行从上到下进行规则匹配的,意味着如果前面的规则匹配的范围更大,则后面的规则将不会生效;</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 示例:</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">(1) foder/* 忽略目录foder下的全部内容,不管是根目录下的 /foder/ 目录,还是某个子目录 /list/foder/
目录,都会被忽略。</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> (2) /foder/* 说明:忽略根目录下的 /foder/ 目录的全部内容;</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> (3) /*</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">!.gitignore</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> !/fw/bin/</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> !/fw/sf/</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 说明:忽略全部内容,但是不忽略 .gitignore文件,根目录下的 /fw/bin/ 和 /fw/sf/ </span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> </span></span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""><span style="margin:0px; padding:0px; color:rgb(255,0,0)">
注意问题:</span></span><span style="margin:0px; padding:0px; color:rgb(255,0,0)"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> .gitignore文件只对还没有加入版本管理的文件起作用,如果之前已经用git把要忽略的文件纳入了版本库,就不起作用了。</span></span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:16px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; color:rgb(0,128,0)">3:如何在同一台电脑上使用两个git账户</span></span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 问题描述:作为程序员有时候是有多个的项目,而且每个项目git的用户名,邮箱等,都不一样。就我来说,我在github上有一个账号,自己开发一些东西,同时我参与的也有项目需要连接别人的github账号,在我电脑上只有一个git客户端,本地一个身份用户,开始的时候我自己开发是用ssh方式,参与的项目的是用https连接,但是https每次都需要输入密码,非常不方便,所以想转成ssh连接,利用命令:</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">>$ git remote rm origin</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">>$ git remote add origin git@github.com:yu/demo.git </span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">>$ git push origin </span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">转换成功,不幸的是push的时候出错了:<span style="margin:0px; padding:0px; color:rgb(255,0,0)">ERROR: Permission to user1 denied to</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">这种情况的解决方式是方法,使用本地托管多个个ssh的密钥,不同的账号是用不同的密匙。</span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">第一步:生成SSH Key</span></span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">执行命令,如下图:</span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-size:15px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""><img src="http://images.cnitblog.com/blog2015/621032/201505/111126256574925.jpg" alt="" style="margin:0px; padding:0px; border:0px; max-width:900px"></span></span></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">具体说明:</span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span> $ ssh-keygen -t rsa -C "your_email@youremail.com"
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span> Creates a <span style="margin:0px; padding:0px; color:rgb(0,0,255); font-size:12px!important; line-height:1.5!important">new</span> ssh <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">key</span> using the provided email Generating <span style="margin:0px; padding:0px; color:rgb(0,0,255); font-size:12px!important; line-height:1.5!important">public</span>/<span style="margin:0px; padding:0px; color:rgb(0,0,255); font-size:12px!important; line-height:1.5!important">private</span> rsa <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">key</span> pair.
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">3</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">#</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">输入将要保存的路径,我的默认为当前路径(/c/Users/zhaoyafei/.ssh/id_rsa),但是不能使用默认文件id_rsa,要添加新账户就要生起一个成新的好记的名字,例如id_rsa_work</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">4</span> Enter <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">file</span> in which to save the <span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">key</span> (/c/Users/zhaoyafei/.ssh/id_rsa):
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">5</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">#</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">输入回车后提示输入一个类似于密码的号,直接回车就行</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">6</span> Enter passphrase (<span style="margin:0px; padding:0px; color:rgb(0,0,255); font-size:12px!important; line-height:1.5!important">empty</span> <span style="margin:0px; padding:0px; color:rgb(0,0,255); font-size:12px!important; line-height:1.5!important">for</span> no passphrase):
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">7</span> Enter same passphrase again:</span></pre>
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-size:16px; font-family:"Microsoft YaHei"">第二步:识别新的私钥</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"> <span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 默认SSH只会读取id_rsa,所以为了让SSH识别新的私钥,需要将其添加到SSH agent </span> </span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:13px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span> ssh-add ~/.ssh/<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">id_rsa_work
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">//</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">该命令如果报错:Could not open a connection to your authentication agent.可执行 ssh-agent bash 命令后再执行ssh-add -l 看是否成功。</span></span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">执行命令,如下图:</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><img src="http://images.cnitblog.com/blog2015/621032/201505/111127561579343.jpg" alt="" style="margin:0px; padding:0px; border:0px; max-width:900px"></span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"> </p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-size:16px; font-family:"Microsoft YaHei"">第三步:修改config文件</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 该文件用于配置私钥对应的服务器。内容如下:</span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:14px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 1</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">#</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important"> Default github (默认的)</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 2</span> Host github.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">com
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 3</span> HostName github.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">com
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 4</span> <span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> User git
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 5</span> IdentityFile ~/.ssh/<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">id_rsa
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 6</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 7</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important">#</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); font-size:12px!important; line-height:1.5!important"> second user(work@gmail.com)</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 8</span> <span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> Host github_work
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important"> 9</span> HostName github.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">com
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">10</span> <span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important"> User git
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">11</span> IdentityFile ~/.ssh/id_rsa_work</span></pre>
<div class="cnblogs_code_toolbar" style="margin:5px 0px 0px; padding:0px"><span class="cnblogs_code_copy" style="margin:0px; padding:0px 5px 0px 0px; line-height:1.5!important"><a target="_blank" title="复制代码" style="margin:0px; padding:0px; color:rgb(73,73,73); font-family:Arial,Helvetica,sans-serif; font-size:14px; text-decoration:underline; border:none!important"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin:0px; padding:0px; max-width:900px; border:none!important"></a></span></div>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"> <span style="margin:0px; padding:0px; font-size:15px; font-family:"Microsoft YaHei""> 这样配置,也就是使用hostname为github.com会根据用户名的不同,去使用不用的private key。github上,也可以添加对应的公钥。其实这个配置是关于ssh的与git无关,只是git使用的方式是ssh的方式。Host可随意,方便自己记忆,后续在添加remote是还需要用到。</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-size:15px; font-family:"Microsoft YaHei"">第四步:将SSH key输入到GitHub网站中</span></span> <br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:15px; font-family:"Microsoft YaHei"">将生成的id_rsa_work.pub输入到GitHub网站中就可以了,输入完成后单击Add key后,会看到git-tutorial已经被添加进去了。 配置完成后,在连接非默认帐号的github仓库时,远程库的地址要对应地做一些修改,比如现在添加abc帐号下的一个仓库test,则需要这样添加:<span style="margin:0px; padding:0px; color:rgb(0,128,0)">git
remote add test git@github-work:abc/test.git #并非原来的git@github.com:abc/test.git</span> 这样每次连接都会使用id_rsa_abc与服务器进行连接。</span></p>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:15px"><span style="margin:0px; padding:0px; color:rgb(255,0,0)"> <span style="margin:0px; padding:0px">注意:</span></span>github根据配置文件的user.email来获取github帐号显示author信息,所以对于多帐号用户一定要记得将user.email改为相应的email(work@mail.com)。我遇到的问题是本地单一用户,链接不同的github账号,所以用户配置可以采用全局配置。如果不同本地用户(不同的身份标识,即需要本地使用不同的用户名),那么git就不要使用有–global的配置,可以按照下面的方法:</span></p>
<div class="cnblogs_code" style="margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:"Courier New"!important; font-size:12px!important">
<pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:"Courier New"!important"><span style="margin:0px; padding:0px; font-size:14px; line-height:1.5!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">1</span> 1)设置局部的user.name和user.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">email
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">2</span> git config user.name "xxxxxx"
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">3</span> git config user.email "xxx@xxx.com"
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">4</span> 2)设置全局的user.name和user.<span style="margin:0px; padding:0px; font-size:12px!important; line-height:1.5!important">email
</span><span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">5</span> git config --global user.name "xxxxxx"
<span style="margin:0px; padding:0px; color:rgb(0,128,128); font-size:12px!important; line-height:1.5!important">6</span> git config –-<span style="margin:0px; padding:0px; line-height:1.5!important">global</span> user.email ""</span></pre>
</div>
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px"><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px; font-size:18px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">六、题外话(相关概念)</span></span></span></p>
<p style="margin:10px auto 10px 30px; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">Git - 版本控制工具</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> Git是一个开源的分布式版本控制系统,用以有效、高速的处理从很小到非常大的项目版本管理。</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">Git 是 Linus Torvalds 为了帮助管理
Linux 内核开发而开发的一个开放源码的版本控制软件。</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">Torvalds 开始着手开发 Git 是为了作为一种过渡方案来替代 BitKeeper,后者之前一直是 Linux 内核开发人员在全球使用的主要源代码工具。开放源码社区中的有些人觉得 BitKeeper 的许可证并不适合开放源码社区的工作,因此 Torvalds 决定着手研究许可证更为灵活的版本控制系统。尽管最初
Git 的开发是为了辅助 Linux 内核开发的过程,但是我们已经发现在很多其他自由软件项目中也使用了 Git。例如 最近就迁移到 Git 上来了,很多 Freedesktop 的项目也迁移到了 Git 上。</span></span></p>
<p style="margin:10px auto 10px 30px; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">Github - 一个网站,提供给用户空间创建git仓储,保存用户的一些数据文档或者代码等</span></span><br style="margin:0px; padding:0px">
<span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei""> 作为开源代码库以及版本控制系统,Github目前拥有140多万开发者用户。随着越来越多的应用程序转移到了云上,Github已经成为了管理软件开发以及发现已有代码的首选方法。</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">如前所述,作为一个分布式的版本控制系统,在Git中并不存在主库这样的概念,每一份复制出的库都可以独立使用,任何两个库之间的不一致之处都可以进行合并。</span><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">GitHub可以托管各种git库,并提供一个web界面,但与其它像
SourceForge或Google Code这样的服务不同,GitHub的独特卖点在于从另外一个项目进行分支的简易性。为一个项目贡献代码非常简单:首先点击项目站点的“fork”的按 钮,然后将代码检出并将修改加入到刚才分出的代码库中,最后通过内建的“pull request”机制向项目负责人申请代码合并。已经有人将GitHub称为代码玩家的MySpace。</span></span></p>
<p style="margin:10px auto 10px 30px; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px"><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; color:rgb(0,128,0)">GitLab - 基于Git的项目管理软件</span></span><br style="margin:0px; padding:0px">
</p>
<p><span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"">GitLab 是一个用于仓库管理系统的开源项目。使用Git作为代码管理工具,并在此基础上搭建起来的web服务。三者都是基于git的,可以说是git的衍生品。</span></p>
<p><span style="font-family:Microsoft YaHei">文章出处:http://www.cnblogs.com/zyf-zhaoyafei/p/4486220.html</span></p>
</div>
</div>
</div>
<!-- Baidu Button BEGIN -->
<div class="bdsharebuttonbox tracking-ad bdshare-button-style0-16" style="float: right;" data-mod="popu_172" data-bd-bind="1505991722359">
<a href="#" class="bds_more" data-cmd="more" style="background-position:0 0 !important; background-image: url(http://bdimg.share.baidu.com/static/api/img/share/icons_0_16.png?v=d754dcc0.png) !important" target="_blank"></a>
<a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间" style="background-position:0 -52px !important" target="_blank"></a>
<a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博" style="background-position:0 -104px !important" target="_blank"></a>
<a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博" style="background-position:0 -260px !important" target="_blank"></a>
<a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网" style="background-position:0 -208px !important" target="_blank"></a>
<a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信" style="background-position:0 -1612px !important" target="_blank"></a>
</div>
<script>window._bd_share_config = { "common": { "bdSnsKey": {}, "bdText": "", "bdMini": "1", "bdMiniList": false, "bdPic": "", "bdStyle": "0", "bdSize": "16" }, "share": {} }; with (document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];</script>
<!-- Baidu Button END -->
<!--172.16.140.11-->
<!-- Baidu Button BEGIN -->
<script type="text/javascript" id="bdshare_js" data="type=tools&uid=1536434" src="http://bdimg.share.baidu.com/static/js/bds_s_v2.js?cdnversion=418332"></script>
<script type="text/javascript">
document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil(new Date()/3600000)
</script>
<!-- Baidu Button END -->
<div id="digg" articleid="74078228">
<dl id="btnDigg" class="digg digg_enable" οnclick="btndigga();">
<dt>顶</dt>
<dd>0</dd>
</dl>
<dl id="btnBury" class="digg digg_enable" οnclick="btnburya();">
<dt>踩</dt>
<dd>0</dd>
</dl>
</div>
<div class="tracking-ad" data-mod="popu_222"><a href="javascript:void(0);" target="_blank"> </a> </div>
<div class="tracking-ad" data-mod="popu_223"> <a href="javascript:void(0);" target="_blank"> </a></div>
<script type="text/javascript">
function btndigga() {
$(".tracking-ad[data-mod='popu_222'] a").click();
}
function btnburya() {
$(".tracking-ad[data-mod='popu_223'] a").click();
}
</script>
<ul class="article_next_prev">
<li class="prev_article"><span οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_shangyipian']);location.href='http://blog.csdn.net/sunayxin/article/details/74078159';">上一篇</span><a href="http://blog.csdn.net/sunayxin/article/details/74078159" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_shangyipian'])">经典的排序算法</a></li>
<li class="next_article"><span οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_xiayipian']);location.href='http://blog.csdn.net/sunayxin/article/details/74079978';">下一篇</span><a href="http://blog.csdn.net/sunayxin/article/details/74079978" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_xiayipian'])">网站第三方登录(php版)</a></li>
</ul>
<div style="clear:both; height:10px;"></div>
<div class="similar_article">
<h4></h4>
<div class="similar_c" style="margin:20px 0px 0px 0px">
<div class="similar_c_t">
相关文章推荐
</div>
<div class="similar_wrap tracking-ad" data-mod="popu_36" style="max-height:250px">
<ul class="similar_list fl">
<li>
<em>•</em>
<a href="http://download.csdn.net/download/doris_d/8494441" title="git学习总结" strategy="BlogCommendFromCsdn_0" target="_blank">git学习总结</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/huiyiCourse/series_detail/64?utm_source=blog7" title="大数据技术实战线上峰会--董西成" strategy="undefined" target="_blank">大数据技术实战线上峰会--董西成</a>
</li>
<li>
<em>•</em>
<a href="http://download.csdn.net/download/wsh19930305/9688055" title="git命令学习总结" strategy="BlogCommendFromCsdn_1" target="_blank">git命令学习总结</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/huiyiCourse/series_detail/61?utm_source=blog7" title="30天系统掌握机器学习--唐宇迪" strategy="undefined" target="_blank">30天系统掌握机器学习--唐宇迪</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/ApplyDev/article/details/52824305" title="Git学习总结" strategy="BlogCommendFromCsdn_2" target="_blank">Git学习总结</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/combo/detail/382?utm_source=blog7" title="ORACLE数据库学习资料集锦" strategy="undefined" target="_blank">ORACLE数据库学习资料集锦</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/shi_weihappy/article/details/42471115" title="Git命令学习总结(-)" strategy="BlogCommendFromCsdn_3" target="_blank">Git命令学习总结(-)</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/course/detail/3010?utm_source=blog7" title="PHP从零开始实战篇" strategy="undefined" target="_blank">PHP从零开始实战篇</a>
</li>
</ul>
<ul class="similar_list fr">
<li>
<em>•</em>
<a href="http://blog.csdn.net/yanxiangyfg/article/details/49947635" title="git学习--gerrit服务器搭建总结" strategy="BlogCommendFromCsdn_4" target="_blank">git学习--gerrit服务器搭建总结</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/course/detail/3149?utm_source=blog7" title="玩转微信小程序第一篇" strategy="undefined" target="_blank">玩转微信小程序第一篇</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/doris_d/article/details/42869363" title="git学习总结" strategy="BlogCommendFromCsdn_5" target="_blank">git学习总结</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/course/detail/4565?utm_source=blog7" title="深度学习案例分享—人脸检测" strategy="undefined" target="_blank">深度学习案例分享—人脸检测</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/weixin_38021928/article/details/70186036" title="Java 版本控制工具-Git 学习总结" strategy="BlogCommendFromCsdn_6" target="_blank">Java 版本控制工具-Git 学习总结</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/tanghua0809/article/details/45726399" title="Android 开发git学习,常用命令总结" strategy="BlogCommendFromCsdn_7" target="_blank">Android 开发git学习,常用命令总结</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/wayne566/article/details/75591901" title="Git入门基本操作学习总结(更新中)" strategy="BlogCommendFromCsdn_8" target="_blank">Git入门基本操作学习总结(更新中)</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/shi923281339/article/details/62425321" title="Git学习总结(一):本地操作" strategy="BlogCommendFromCsdn_9" target="_blank">Git学习总结(一):本地操作</a>
</li>
</ul>
</div>
</div>
</div>
</div>