Git reset介绍

<div id="main">
                <div class="main">
                        <div class="ad_class">
<div class="notice tracking-ad" data-mod="popu_3">


<a href="http://blog.csdn.net/blogdevteam/article/details/66974343" target="_blank">
<font color="blue">CSDN日报20170327——《如何平衡工作与生活?真相在此》</font></a>

&nbsp;&nbsp;&nbsp;&nbsp;

<a href="http://www.bagevent.com/event/469757" target="_blank">
<font color="red">CSDN 知识小饭桌:Python 进阶 Q &amp; A
</font></a>
&nbsp;&nbsp;&nbsp;&nbsp;

<a href="http://blog.csdn.net/turingbooks/article/details/65631771" target="_blank">
<font color="blue">程序员3月书讯
</font></a>
</div>                        </div>
                        



 
<link href="http://static.blog.csdn.net/css/comment1.css" type="text/css" rel="stylesheet">
<link href="http://static.blog.csdn.net/css/style1.css" type="text/css" rel="stylesheet">
<script language="JavaScript" type="text/javascript" src="http://download.csdn.net/js/jquery.cookie.js"></script>
<script type="text/javascript" src="http://c.csdnimg.cn/rabbit/search-service/main.js"></script>
<link rel="stylesheet" href="http://static.blog.csdn.net/public/res-min/markdown_views.css?v=1.0">
<link rel="stylesheet" href="http://static.blog.csdn.net/css/category.css?v=1.0">
<script type="text/javascript" src="http://static.blog.csdn.net/public/res/bower-libs/MathJax/MathJax.js?config=TeX-AMS_HTML"></script>
<script type="text/javascript" src="http://static.blog.csdn.net/scripts/web-storage-cache.min.js"></script>
<script type="text/javascript" src="http://static.blog.csdn.net/scripts/replace.min.js"></script>

<link rel="stylesheet" href="http://static.blog.csdn.net/code/prettify.css">
<script type="text/javascript" src="http://static.blog.csdn.net/code/prettify.js"></script>


  <script type="text/ecmascript">
      window.quickReplyflag = true;
           
            var isBole = false;
            
      
      var fasrc="http://my.csdn.net/my/favorite/miniadd?t=git+reset%e7%ae%80%e4%bb%8b&u=http://blog.csdn.net/hudashi/article/details/7664464/"

    </script>
<div id="article_details" class="details">
    <div class="article_title">   
         <span class="ico ico_type_Repost"></span>


    <h1>
        <span class="link_title"><a href="/hudashi/article/details/7664464">
        git reset简介            
        </a></span>
    </h1>
</div>

   

        <div class="article_manage clearfix">
        <div class="article_l">
            <span class="link_categories">
            标签:
              <a href="http://www.csdn.net/tag/git" target="_blank" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_tag']);">git</a><a href="http://www.csdn.net/tag/branch" target="_blank" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_tag']);">branch</a><a href="http://www.csdn.net/tag/tree" target="_blank" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_tag']);">tree</a><a href="http://www.csdn.net/tag/merge" target="_blank" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_tag']);">merge</a><a href="http://www.csdn.net/tag/conflict" target="_blank" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_tag']);">conflict</a><a href="http://www.csdn.net/tag/file" target="_blank" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_tag']);">file</a>
            </span>
        </div>
        <div class="article_r">
            <span class="link_postdate">2012-06-14 20:58</span>
            <span class="link_view" title="阅读次数">149390人阅读</span>
            <span class="link_comments" title="评论次数"> <a href="#comments" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_pinglun'])">评论</a>(5)</span>
            <span class="link_collect tracking-ad" data-mod="popu_171"> <a href="javascript:void(0);" οnclick="javascript:collectArticle('git+reset%e7%ae%80%e4%bb%8b','7664464');return false;" title="收藏" target="_blank">收藏</a></span>
             <span class="link_report"> <a href="#report" οnclick="javascript:report(7664464,2);return false;" title="举报">举报</a></span>

        </div>
    </div>
    <div class="embody" style="" id="embody">
        <span class="embody_t">本文章已收录于:</span>
        <div class="embody_c" id="lib" value="{&quot;err&quot;:0,&quot;msg&quot;:&quot;ok&quot;,&quot;data&quot;:[{&quot;name&quot;:&quot;Git知识库&quot;,&quot;url&quot;:&quot;http://lib.csdn.net/base/28?source=blogtop&quot;,&quot;logo&quot;:&quot;http://img.knowledge.csdn.net/upload/base/1460535308634_634.jpg&quot;}]}"> <a href="http://lib.csdn.net/base/28?source=blogtop" target="_blank"> <img src="http://img.knowledge.csdn.net/upload/base/1460535308634_634.jpg"> <em><b>Git知识库</b></em> </a></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 + "&nbsp;&nbsp;";
                        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 οnclick="GetCategoryArticles('1122124','hudashi','top','7664464');">
                        <span οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_fenlei']);">版本控制<em>(50)</em></span>
                      <img class="arrow-down" src="http://static.blog.csdn.net/images/arrow_triangle _down.jpg" style="display: inline;">
                      <img class="arrow-up" src="http://static.blog.csdn.net/images/arrow_triangle_up.jpg" style="display: none;">
                        <div class="subItem" style="display: none;">
                            <div class="subItem_t"><a href="http://blog.csdn.net/hudashi/article/category/1122124" target="_blank">作者同类文章</a><i class="J_close">X</i></div>
                            <ul class="subItem_l" id="top_1122124"><li class="tracking-ad" data-mod="popu_140"><em>•</em><a href="http://blog.csdn.net/hudashi/article/details/54668359" id="top_aritcle_54668359undefined756418236451111" target="_blank" title="如何搭建开源code review gerrit服务器">如何搭建开源code review gerrit服务器</a></li> <li class="tracking-ad" data-mod="popu_140"><em>•</em><a href="http://blog.csdn.net/hudashi/article/details/53789368" id="top_aritcle_53789368undefined5195117635589378" target="_blank" title="关于git的ssh-key:解决本地多个ssh-key的问题">关于git的ssh-key:解决本地多个ssh-key的问题</a></li> <li class="tracking-ad" data-mod="popu_140"><em>•</em><a href="http://blog.csdn.net/hudashi/article/details/53259646" id="top_aritcle_53259646undefined694974261739242" target="_blank" title="no matching key exchange method found. Their offer: diffie-hellman-group1-sha1">no matching key exchange method found. Their offer: diffie-hellman-group1-sha1</a></li> <li class="tracking-ad" data-mod="popu_140"><em>•</em><a href="http://blog.csdn.net/hudashi/article/details/53130689" id="top_aritcle_53130689undefined7708816892751773" target="_blank" title="【Gerrit】添加git工程到gerrit服务器">【Gerrit】添加git工程到gerrit服务器</a></li> <li class="tracking-ad" data-mod="popu_140"><em>•</em><a href="http://blog.csdn.net/hudashi/article/details/51782560" id="top_aritcle_51782560undefined362936458621835" target="_blank" title=".gitignore简介">.gitignore简介</a></li> <li style="padding-left: 300px;"><a href="http://blog.csdn.net/hudashi/article/category/1122124" target="_blank">更多</a></li></ul>
                        </div>
                    </label>                    
        </div>
    </div>
    <script type="text/javascript" src="http://static.blog.csdn.net/scripts/category.js"></script>  

 

 
 
     

<div style="clear:both"></div><div style="border:solid 1px #ccc; background:#eee; float:left; min-width:200px;padding:4px 10px;"><p style="text-align:right;margin:0;"><span style="float:left;">目录<a href="#" title="系统根据文章中H1到H6标签自动生成文章目录">(?)</a></span><a href="#" οnclick="javascript:return openct(this);" title="展开">[+]</a></p><ol style="margin-left: 14px; padding-left: 14px; line-height: 160%; display: none;"><li><a href="#t0">
DESCRIPTION</a></li><li><a href="#t1">
OPTIONS</a></li><li><a href="#t2">
EXAMPLES</a></li><li><a href="#t3">
DISCUSSION</a></li></ol></div><div style="clear:both"></div><div id="article_content" class="article_content">

<span style="font-family:Arial,Helvetica,simsun,u5b8bu4f53; font-size:14px; line-height:25px; background-color:rgb(245,245,245)">本文编辑整理自:<a rel="nofollow" href="http://guibin.iteye.com/blog/1014369" style="color:rgb(245,149,19); line-height:25px; text-decoration:none">http://guibin.iteye.com/blog/1014369</a></span>
<div style="line-height:25px"><a rel="nofollow" href="http://hi.baidu.com/tiger_tnt/blog/item/a0464ffa6a8115d9b58f314d.html" style="color:rgb(245,149,19); line-height:25px; text-decoration:none">http://hi.baidu.com/tiger_tnt/blog/item/a0464ffa6a8115d9b58f314d.html</a></div>
<div style="line-height:25px"><a rel="nofollow" href="http://web.mit.edu/~mkgray/project/silk/root/afs/sipb/project/git/git-doc/git-reset.html" style="color:rgb(245,149,19); line-height:25px; text-decoration:none">http://web.mit.edu/~mkgray/project/silk/root/afs/sipb/project/git/git-doc/git-reset.html</a><br style="line-height:25px">
<div style="line-height:25px">
<div style="line-height:25px"><span style="line-height:25px"><span style="font-size:16px; line-height:28px">一、基本篇</span></span></div>
<div style="line-height:25px">在git的一般使用中,如果发现错误的将不想staging的文件add进入index之后,想回退取消,则可以使用命令:git reset HEAD &lt;file&gt;...,同时git add完毕之后,git也会做相应的提示,比如:</div>
<div style="line-height:25px">引用</div>
<div style="line-height:25px">
<pre class="prettyprint" style="line-height:25px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)" name="code"><p style="line-height:25px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"></p><div style="line-height:25px"><span class="com" style="line-height:25px; color:rgb(136,0,0)"># Changes to be committed:&nbsp;</span></div><div style="line-height:25px"><span class="com" style="line-height:25px; color:rgb(136,0,0)"># &nbsp; (use "git reset HEAD &lt;file&gt;..." to unstage)&nbsp;</span></div><div style="line-height:25px"><span class="com" style="line-height:25px; color:rgb(136,0,0)">#&nbsp;</span></div><div style="line-height:25px"><span class="com" style="line-height:25px; color:rgb(136,0,0)">#</span><span style="line-height:25px; white-space:pre"><span class="com" style="line-height:25px; color:rgb(136,0,0)"> </span></span><span class="com" style="line-height:25px; color:rgb(136,0,0)">new file: &nbsp; Test.scala&nbsp;</span></div><p style="line-height:25px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"></p><div class="save_code tracking-ad" data-mod="popu_249" style="display: none;"><a href="javascript:;" target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png"></a></div></pre>
</div>
<div style="line-height:25px"><span style="color:#800000; line-height:25px">git reset&nbsp;</span>[<span style="color:#800000; line-height:25px">--hard|soft|mixed|merge|keep</span>]<span style="color:#800000; line-height:25px">&nbsp;[&lt;commit&gt;</span><span style="color:#000080; line-height:25px">或</span><span style="color:#800000; line-height:25px">HEAD]</span>:将当前的分支重设(reset)到指定的&lt;commit&gt;或者HEAD(默认,如果不显示指定commit,默认是HEAD,即最新的一次提交),并且根据[mode]有可能更新index和working
 directory。mode的取值可以是<span style="color:#993300; line-height:25px">hard、soft、mixed、merged、keep</span>。下面来详细说明每种模式的意义和效果。</div>
<div style="line-height:25px"><span style="line-height:25px">A).</span><span style="color:#993300; line-height:25px">&nbsp;--hard</span>:重设(reset) index和working directory,自从&lt;commit&gt;以来在working directory中的任何改变都被丢弃,并把HEAD指向&lt;commit&gt;。&nbsp;</div>
<div style="line-height:25px">
<div style="line-height:22px"><span style="color:#000080; line-height:22px">具体一个例子,假设有三个commit, git st:</span></div>
<div style="line-height:22px">
<pre class="prettyprint" style="line-height:22px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)" name="code"><p style="line-height:22px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; color:rgb(0,0,128)"></p><div style="line-height:22px"><span style="color:#3366ff; line-height:22px"><span class="pln" style="line-height:25px; color:rgb(0,0,0)">commit3</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">:</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)"> add test3</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">.</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)">c</span></span></div><div style="line-height:22px"><span style="color:#3366ff; line-height:22px"><span class="pln" style="line-height:25px; color:rgb(0,0,0)">commit2</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">:</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)"> add test2</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">.</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)">c</span></span></div><div style="line-height:22px"><span style="color:#3366ff; line-height:22px"><span class="pln" style="line-height:25px; color:rgb(0,0,0)">commit1</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">:</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)"> add test1</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">.</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)">c</span></span></div><p style="line-height:22px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; color:rgb(0,0,128)"></p><div class="save_code tracking-ad" data-mod="popu_249" style="display: none;"><a href="javascript:;" target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png"></a></div></pre>
</div>
<div style="line-height:25px">
<div style="line-height:25px; color:rgb(0,0,128)">执行git reset --hard HEAD~1后,</div>
<div style="line-height:25px; color:rgb(0,0,128)">显示:HEAD is now at commit2,运行git log</div>
<div style="line-height:25px"><span style="color:#3366ff; line-height:25px"></span>
<pre class="prettyprint" style="line-height:25px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)" name="code"><p style="line-height:25px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"></p><div style="line-height:25px"><span style="color:#3366ff; line-height:25px"><span class="pln" style="line-height:25px; color:rgb(0,0,0)">commit2</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">:</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)"> add test2</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">.</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)">c</span></span></div><div style="line-height:25px"><span style="color:#3366ff; line-height:25px"><span class="pln" style="line-height:25px; color:rgb(0,0,0)">commit1</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">:</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)"> add test1</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">.</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)">c</span></span></div><p style="line-height:25px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"></p><div class="save_code tracking-ad" data-mod="popu_249" style="display: none;"><a href="javascript:;" target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets_01.png"></a></div></pre>
</div>
<div style="line-height:25px; color:rgb(0,0,128)">运行git st, 没有任何变化</div>
</div>
</div>
<div style="line-height:25px"><span style="line-height:25px">B)</span>.&nbsp;<span style="color:#993300; line-height:25px">--soft</span>:index和working directory中的内容不作任何改变,仅仅把HEAD指向&lt;commit&gt;。这个模式的效果是,执行完毕后,自从&lt;commit&gt;以来的所有改变都会显示在git status的"Changes to be committed"中。&nbsp;</div>
<div style="line-height:25px">
<div style="line-height:25px"><span style="color:#000080; line-height:25px">具体一个例子,假设有三个commit, git st:</span></div>
<div style="line-height:25px">
<pre class="prettyprint" style="line-height:25px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)" name="code"><p style="line-height:25px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; color:rgb(0,0,128)"></p><div style="line-height:25px"><span style="color:#3366ff; line-height:25px"><span class="pln" style="line-height:25px; color:rgb(0,0,0)">commit3</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">:</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)"> add test3</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">.</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)">c</span></span></div><div style="line-height:25px"><span style="color:#3366ff; line-height:25px"><span class="pln" style="line-height:25px; color:rgb(0,0,0)">commit2</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">:</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)"> add test2</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">.</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)">c</span></span></div><div style="line-height:25px"><span style="color:#3366ff; line-height:25px"><span class="pln" style="line-height:25px; color:rgb(0,0,0)">commit1</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">:</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)"> add test1</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">.</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)">c</span></span></div><p style="line-height:25px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; color:rgb(0,0,128)"></p><div class="save_code tracking-ad" data-mod="popu_249" style="display: none;"><a href="javascript:;" target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png"></a></div></pre>
</div>
<div style="line-height:25px"><span style="color:#000080; line-height:25px">执行git reset --soft(默认) HEAD~1后,运行git log</span></div>
<div style="line-height:25px"><span style="color:#3366ff; line-height:25px"></span>
<pre class="prettyprint" style="line-height:25px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)" name="code"><p style="line-height:25px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"></p><div style="line-height:25px"><span style="color:#3366ff; line-height:25px"><span class="pln" style="line-height:25px; color:rgb(0,0,0)">commit2</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">:</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)"> add test2</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">.</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)">c</span></span></div><div style="line-height:25px"><span style="color:#3366ff; line-height:25px"><span class="pln" style="line-height:25px; color:rgb(0,0,0)">commit1</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">:</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)"> add test1</span><span class="pun" style="line-height:25px; color:rgb(102,102,0)">.</span><span class="pln" style="line-height:25px; color:rgb(0,0,0)">c</span></span></div><p style="line-height:25px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"></p><div class="save_code tracking-ad" data-mod="popu_249" style="display: none;"><a href="javascript:;" target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets_01.png"></a></div></pre>
</div>
<div style="line-height:25px"><span style="color:#000080; line-height:25px">运行git status, 则test3.c处于暂存区,处于准备提交状态。即此时git commit就会提交它。</span></div>
</div>
<div style="line-height:25px">
<div style="line-height:25px; color:rgb(0,0,128)">&nbsp; 在使用git进行协作开发时,我们经常需要将自己的修改生成patch发给被人,但是在修改代码的过程中我们进行了很多次的提交,如何生成从最初的代码状态到最终代码状态的patch呢?下面要介绍的功能是应对这中情况。</div>
<div style="line-height:25px; color:rgb(0,0,128)">现假设我们git软件仓库中的分支情况如下:</div>
<div style="line-height:25px"><span style="color:#3366ff; line-height:25px">a--&gt;b--&gt;c</span></div>
<div style="line-height:25px; color:rgb(0,0,128)">也就是说我们的代码从状态a修改到状态b,进行一次提交,然后再修改到状态c,进行一次提交。这时我们已经肯定由a到c的修改是正确的,不再需要状态b了,并且要把从a到c的变化生成一个patch发送给别人。如果直接打包的话会生成两个path,那么如何生成一个patch呢,这时就需要git-reset命令。</div>
<div style="line-height:25px; color:rgb(0,0,128)">首先给状态a创建一个tag,假设名称为A,然后执行</div>
<div style="line-height:25px"><span style="color:#3366ff; line-height:25px">git-reset --soft A</span></div>
<div style="line-height:25px; color:rgb(0,0,128)">这样我们的软件仓库就变为</div>
<div style="line-height:25px"><span style="color:#0000ff; line-height:25px">a</span></div>
<div style="line-height:25px; color:rgb(0,0,128)">状态b和状态c都已经被删除了,但是当前的代码并没有被改变,还是状态c的代码,这时我们做一次提交,软件仓库变成下面的样子:</div>
<div style="line-height:25px"><span style="color:#3366ff; line-height:25px">a--&gt;d</span></div>
<div style="line-height:25px; color:rgb(0,0,128)">状态d和状态c所对应的代码是完全相同的,只是名字不同。现在就可以生成一个patch打包发给别人了</div>
</div>
<div style="line-height:25px"><span style="line-height:25px">C)</span>.&nbsp;<span style="color:#993300; line-height:25px">--mixed</span>:仅reset index,但是不reset working directory。这个模式是默认模式,即当不显示告知git reset模式时,会使用mixed模式。这个模式的效果是,working directory中文件的修改都会被保留,不会丢弃,<span style="color:#000080; line-height:25px">但是也不会被标记成"Changes
 to be committed"</span>,但是会打出什么还未被更新的报告。报告如下:&nbsp;</div>
<div style="line-height:25px">引用</div>
<div style="line-height:25px">Unstaged changes after reset:&nbsp;</div>
<div style="line-height:25px">M<span style="line-height:25px; white-space:pre"> </span>
Test.Scala&nbsp;</div>
<div style="line-height:25px">M<span style="line-height:25px; white-space:pre"> </span>
test.txt</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px"><span style="line-height:25px">D)</span>.&nbsp;<span style="color:#993300; line-height:25px">--merge</span>和<span style="color:#993300; line-height:25px">--keep</span>用的不多,在下面的例子中说明。&nbsp;</div>
<div style="line-height:25px"><span style="line-height:25px"><span style="font-size:16px; line-height:28px">二、常用示例</span></span></div>
<div style="line-height:25px">下面列出一些git reset的典型的应用场景:&nbsp;</div>
<div style="line-height:25px">A) 回滚add操纵&nbsp;</div>
<div style="line-height:25px">引用</div>
<div style="line-height:25px">$ edit &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (1)&nbsp;</div>
<div style="line-height:25px">$ git add frotz.c filfre.c&nbsp;</div>
<div style="line-height:25px">$ mailx &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(2)&nbsp;</div>
<div style="line-height:25px">$ git reset &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(3)&nbsp;</div>
<div style="line-height:25px">$ git pull git://info.example.com/ nitfol &nbsp;(4)&nbsp;</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px">(1) 编辑文件frotz.c, filfre.c,做了些更改,并把更改添加到了index&nbsp;</div>
<div style="line-height:25px">(2) 查看邮件,发现某人要你pull,有一些改变需要你merge下来&nbsp;</div>
<div style="line-height:25px">(3) 然而,你已经把index搞乱了,因为index同HEAD commit不匹配了,但是你知道,即将pull的东西不会影响已经修改的frotz.c和filfre.c,因此你可以revert这两个文件的改变。revert后,那些改变应该依旧在working directory中,因此执行git reset。&nbsp;</div>
<div style="line-height:25px">(4) 然后,执行了pull之后,自动merge,frotz.c和filfre.c这些改变依然在working directory中。&nbsp;</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px">B) 回滚最近一次commit&nbsp;</div>
<div style="line-height:25px">引用</div>
<div style="line-height:25px">$ git commit ...&nbsp;</div>
<div style="line-height:25px">$ git reset --soft HEAD^ &nbsp; &nbsp; &nbsp;(1)&nbsp;</div>
<div style="line-height:25px">$ edit &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(2)&nbsp;</div>
<div style="line-height:25px">$ git commit -a -c ORIG_HEAD &nbsp;(3)&nbsp;</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px">(1) 当提交了之后,你又发现代码没有提交完整,或者你想重新编辑一下提交的comment,执行git reset --soft HEAD^,让working tree还跟reset之前一样,不作任何改变。&nbsp;</div>
<div style="line-height:25px">HEAD^指向HEAD之前最近的一次commit。&nbsp;</div>
<div style="line-height:25px">(2) 对working tree下的文件做修改&nbsp;</div>
<div style="line-height:25px">(3) 然后使用reset之前那次commit的注释、作者、日期等信息重新提交。注意,当执行git reset命令时,git会把老的HEAD拷贝到文件.git/ORIG_HEAD中,在命令中可以使用ORIG_HEAD引用这个commit。commit 命令中 -a 参数的意思是告诉git,自动把所有修改的和删除的文件都放进stage area,未被git跟踪的新建的文件不受影响。commit命令中-c &lt;commit&gt; 或者 -C &lt;commit&gt;意思是拿已经提交的commit对象中的信息(作者,提交者,注释,时间戳等)提交,那么这条commit命令的意思就非常清晰了,把所有更改的文件加入stage
 area,并使用上次的提交信息重新提交。&nbsp;</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px">C) 回滚最近几次commit,并把这几次commit放到叫做topic的branch上去。&nbsp;</div>
<div style="line-height:25px">引用</div>
<div style="line-height:25px">$ git branch topic/wip &nbsp; &nbsp; (1)&nbsp;</div>
<div style="line-height:25px">$ git reset --hard HEAD~3 &nbsp;(2)&nbsp;</div>
<div style="line-height:25px">$ git checkout topic/wip &nbsp; (3)</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px">(1) 你已经提交了一些commit,但是此时发现这些commit还不够成熟,不能进入master分支,但你希望在新的branch上润色这些commit改动。因此执行了git branch命令在当前的HEAD上建立了新的叫做 topic/wip的分支。&nbsp;</div>
<div style="line-height:25px">(2) 然后回滚master branch上的最近三次提交。HEAD~3指向当前HEAD-3个commit的commit,git reset --hard HEAD~3即删除最近的三个commit(删除HEAD, HEAD^, HEAD~2),将HEAD指向HEAD~3。&nbsp;</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px">D) 永久删除最后几个commit&nbsp;</div>
<div style="line-height:25px">引用</div>
<div style="line-height:25px">$ git commit ...&nbsp;</div>
<div style="line-height:25px">$ git reset --hard HEAD~3 &nbsp; (1)</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px">(1) 最后三个commit(即HEAD, HEAD^和HEAD~2)提交有问题,你想永久删除这三个commit。&nbsp;</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px">E) 回滚merge和pull操作&nbsp;</div>
<div style="line-height:25px">引用</div>
<div style="line-height:25px">$ git pull &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (1)&nbsp;</div>
<div style="line-height:25px">Auto-merging nitfol&nbsp;</div>
<div style="line-height:25px">CONFLICT (content): Merge conflict in nitfol&nbsp;</div>
<div style="line-height:25px">Automatic merge failed; fix conflicts and then commit the result.&nbsp;</div>
<div style="line-height:25px">$ git reset --hard &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (2)&nbsp;</div>
<div style="line-height:25px">$ git pull . topic/branch &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(3)&nbsp;</div>
<div style="line-height:25px">Updating from 41223... to 13134...&nbsp;</div>
<div style="line-height:25px">Fast-forward&nbsp;</div>
<div style="line-height:25px">$ git reset --hard ORIG_HEAD &nbsp; &nbsp; &nbsp; (4)</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px">(1) 从origin拉下来一些更新,但是产生了很多冲突,你暂时没有这么多时间去解决这些冲突,因此你决定稍候有空的时候再重新pull。&nbsp;</div>
<div style="line-height:25px">(2) 由于pull操作产生了冲突,因此所有pull下来的改变尚未提交,仍然再stage area中,这种情况下git reset --hard 与 git reset --hard HEAD意思相同,即都是清除index和working tree中被搞乱的东西。&nbsp;</div>
<div style="line-height:25px">(3) 将topic/branch合并到当前的branch,这次没有产生冲突,并且合并后的更改自动提交。&nbsp;</div>
<div style="line-height:25px">(4) 但是此时你又发现将topic/branch合并过来为时尚早,因此决定退滚merge,执行git reset --hard ORIG_HEAD回滚刚才的pull/merge操作。说明:前面讲过,执行git reset时,git会把reset之前的HEAD放入.git/ORIG_HEAD文件中,命令行中使用ORIG_HEAD引用这个commit。同样的,执行pull和merge操作时,git都会把执行操作前的HEAD放入ORIG_HEAD中,以防回滚操作。&nbsp;</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px">F) 在被污染的working tree中回滚merge或者pull&nbsp;</div>
<div style="line-height:25px">引用</div>
<div style="line-height:25px">$ git pull &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (1)&nbsp;</div>
<div style="line-height:25px">Auto-merging nitfol&nbsp;</div>
<div style="line-height:25px">Merge made by recursive.&nbsp;</div>
<div style="line-height:25px">nitfol &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; 20 +++++----&nbsp;</div>
<div style="line-height:25px">...&nbsp;</div>
<div style="line-height:25px">$ git reset --merge ORIG_HEAD &nbsp; &nbsp; &nbsp;(2)</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px">(1) 即便你已经在本地更改了一些你的working tree,你也可安全的git pull,前提是你知道将要pull的内容不会覆盖你的working tree中的内容。&nbsp;</div>
<div style="line-height:25px">(2) git pull完后,你发现这次pull下来的修改不满意,想要回滚到pull之前的状态,从前面的介绍知道,我们可以执行git reset --hard ORIG_HEAD,但是这个命令有个副作用就是清空你的working tree,即丢弃你的本地未add的那些改变。为了避免丢弃working tree中的内容,可以使用git reset --merge ORIG_HEAD,注意其中的--hard 换成了 --merge,这样就可以避免在回滚时清除working
 tree。&nbsp;</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px">G) 被中断的工作流程&nbsp;</div>
<div style="line-height:25px">在实际开发中经常出现这样的情形:你正在开发一个大的feature,此时来了一个紧急的bug需要修复,但是目前在working tree中的内容还没有成型,还不足以commit,但是你又必须切换的另外的branch去fix bug。请看下面的例子&nbsp;</div>
<div style="line-height:25px">引用</div>
<div style="line-height:25px">$ git checkout feature ;# you were working in "feature" branch and&nbsp;</div>
<div style="line-height:25px">$ work work work &nbsp; &nbsp; &nbsp; ;# got interrupted&nbsp;</div>
<div style="line-height:25px">$ git commit -a -m "snapshot WIP" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (1)&nbsp;</div>
<div style="line-height:25px">$ git checkout master&nbsp;</div>
<div style="line-height:25px">$ fix fix fix&nbsp;</div>
<div style="line-height:25px">$ git commit ;# commit with real log&nbsp;</div>
<div style="line-height:25px">$ git checkout feature&nbsp;</div>
<div style="line-height:25px">$ git reset --soft HEAD^ ;# go back to WIP state &nbsp;(2)&nbsp;</div>
<div style="line-height:25px">$ git reset &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (3)</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px">(1) 这次属于临时提交,因此随便添加一个临时注释即可。&nbsp;</div>
<div style="line-height:25px">(2) 这次reset删除了WIP commit,并且把working tree设置成提交WIP快照之前的状态。&nbsp;</div>
<div style="line-height:25px">(3) 此时,在index中依然遗留着“snapshot WIP”提交时所做的uncommit changes,git reset将会清理index成为尚未提交"snapshot WIP"时的状态便于接下来继续工作。&nbsp;</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px">(H) Reset单独的一个文件&nbsp;</div>
<div style="line-height:25px">假设你已经添加了一个文件进入index,但是而后又不打算把这个文件提交,此时可以使用git reset把这个文件从index中去除。&nbsp;</div>
<div style="line-height:25px">引用</div>
<div style="line-height:25px">$ git reset -- frotz.c &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(1)&nbsp;</div>
<div style="line-height:25px">$ git commit -m "Commit files in index" &nbsp; &nbsp; (2)&nbsp;</div>
<div style="line-height:25px">$ git add frotz.c &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (3)</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px">(1) 把文件frotz.c从index中去除,&nbsp;</div>
<div style="line-height:25px">(2) 把index中的文件提交&nbsp;</div>
<div style="line-height:25px">(3) 再次把frotz.c加入index&nbsp;</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px">(I) 保留working tree并丢弃一些之前的commit&nbsp;</div>
<div style="line-height:25px">假设你正在编辑一些文件,并且已经提交,接着继续工作,但是现在你发现当前在working tree中的内容应该属于另一个branch,与这之前的commit没有什么关系。此时,你可以开启一个新的branch,并且保留着working tree中的内容。&nbsp;</div>
<div style="line-height:25px">引用</div>
<div style="line-height:25px">$ git tag start&nbsp;</div>
<div style="line-height:25px">$ git checkout -b branch1&nbsp;</div>
<div style="line-height:25px">$ edit&nbsp;</div>
<div style="line-height:25px">$ git commit ... &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(1)&nbsp;</div>
<div style="line-height:25px">$ edit&nbsp;</div>
<div style="line-height:25px">$ git checkout -b branch2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (2)&nbsp;</div>
<div style="line-height:25px">$ git reset --keep start &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(3)</div>
<div style="line-height:25px"><br style="line-height:25px">
</div>
<div style="line-height:25px">(1) 这次是把在branch1中的改变提交了。&nbsp;</div>
<div style="line-height:25px">(2) 此时发现,之前的提交不属于这个branch,此时你新建了branch2,并切换到了branch2上。&nbsp;</div>
<div style="line-height:25px">(3) 此时你可以用reset --keep把在start之后的commit清除掉,但是保持working tree不变。&nbsp;</div>
<div style="line-height:25px"><span style="line-height:25px"><span style="font-size:16px; line-height:28px">三、高级篇</span></span></div>
<div style="line-height:25px"><span style="line-height:31px; color:rgb(82,123,189); font-family:sans-serif; font-size:24px"><strong>语法</strong></span></div>
<div style="line-height:25px"><span style="line-height:normal; font-family:Simsun; font-size:16px"></span>
<div style="line-height:28px; font-family:serif; margin-left:5%">
<div style="line-height:28px; margin-top:1em; margin-bottom:1.5em; padding-left:1em; margin-left:1em; margin-right:10%; border-left-width:5px; border-left-style:solid; border-left-color:rgb(221,221,221); color:rgb(119,119,119)">
<div style="line-height:28px; white-space:pre"><span style="line-height:28px; color:navy"><em>git reset</em></span> [-q] [&lt;commit&gt;] [--] &lt;paths&gt;…
<span style="line-height:28px; color:navy"><em>git reset</em></span> (--patch | -p) [&lt;commit&gt;] [--] [&lt;paths&gt;…]
<span style="line-height:28px; color:navy"><em>git reset</em></span> (--soft | --mixed | --hard | --merge | --keep) [-q] [&lt;commit&gt;]</div>
<div style="line-height:28px; padding-top:0.75em; text-align:left"></div>
</div>
</div>
<h2 id="_description" style="line-height:1.3; color:rgb(82,123,189); font-family:sans-serif; margin-top:1.2em; margin-bottom:0.5em; border-bottom-width:2px; border-bottom-style:none; border-bottom-color:silver; padding-top:0.5em; border-top-style:none; border-right-style:none; border-left-style:none"><a name="t0"></a>
DESCRIPTION</h2>
<div style="line-height:28px; font-family:serif; margin-left:5%">
<div style="line-height:28px">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
In the first and second form, copy entries from &lt;commit&gt; to the index. In the third form, set the current branch head (HEAD) to &lt;commit&gt;, optionally modifying index and working tree to match. The &lt;commit&gt; defaults to HEAD in all forms.</p>
</div>
<div style="line-height:28px">
<dl style="line-height:28px; margin-top:0.8em; margin-bottom:0.8em"><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
<span style="line-height:28px; color:navy"><em>git reset</em></span>&nbsp;[-q] [&lt;commit&gt;] [--] &lt;paths&gt;…</dt><dd style="line-height:28px">
<p style="line-height:28px; margin-top:0.1em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
This form resets the index entries for all &lt;paths&gt; to their state at &lt;commit&gt;. (It does not affect the working tree, nor the current branch.)</p>
<div style="line-height:28px">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
This means that&nbsp;<tt style="line-height:23px; color:navy"><a href="http://lib.csdn.net/base/git" class="replace_word" title="Git知识库" target="_blank" style="color:#df3434; font-weight:bold;">Git</a> reset &lt;paths&gt;</tt>&nbsp;is the opposite of&nbsp;<tt style="line-height:23px; color:navy">git add &lt;paths&gt;</tt>.</p>
</div>
<div style="line-height:28px">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
After running&nbsp;<tt style="line-height:23px; color:navy">git reset &lt;paths&gt;</tt>&nbsp;to update the index entry, you can use&nbsp;<a rel="nofollow" href="http://web.mit.edu/~mkgray/project/silk/root/afs/sipb/project/git/git-doc/git-checkout.html" style="color:blue; line-height:28px; text-decoration:underline">git-checkout(1)</a>&nbsp;to
 check the contents out of the index to the working tree. Alternatively, using&nbsp;<a rel="nofollow" href="http://web.mit.edu/~mkgray/project/silk/root/afs/sipb/project/git/git-doc/git-checkout.html" style="color:blue; line-height:28px; text-decoration:underline">git-checkout(1)</a>&nbsp;and
 specifying a commit, you can copy the contents of a path out of a commit to the index and to the working tree in one <a href="http://lib.csdn.net/base/go" class="replace_word" title="Go知识库" target="_blank" style="color:#df3434; font-weight:bold;">Go</a>.</p>
</div>
</dd><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
<span style="line-height:28px; color:navy"><em>git reset</em></span>&nbsp;(--patch | -p) [&lt;commit&gt;] [--] [&lt;paths&gt;…]</dt><dd style="line-height:28px">
<p style="line-height:28px; margin-top:0.1em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Interactively select hunks in the difference between the index and &lt;commit&gt; (defaults to HEAD). The chosen hunks are applied in reverse to the index.</p>
<div style="line-height:28px">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
This means that&nbsp;<tt style="line-height:23px; color:navy">git reset -p</tt>&nbsp;is the opposite of&nbsp;<tt style="line-height:23px; color:navy">git add -p</tt>, i.e. you can use it to selectively reset hunks. See the “Interactive Mode” section of&nbsp;<a rel="nofollow" href="http://web.mit.edu/~mkgray/project/silk/root/afs/sipb/project/git/git-doc/git-add.html" style="color:blue; line-height:28px; text-decoration:underline">git-add(1)</a>&nbsp;to
 learn how to operate the&nbsp;<tt style="line-height:23px; color:navy">--patch</tt>&nbsp;mode.</p>
</div>
</dd><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
<span style="line-height:28px; color:navy"><em>git reset</em></span>&nbsp;--&lt;mode&gt; [&lt;commit&gt;]</dt><dd style="line-height:28px">
<p style="line-height:28px; margin-top:0.1em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
This form resets the current branch head to &lt;commit&gt; and possibly updates the index (resetting it to the tree of &lt;commit&gt;) and the working tree depending on &lt;mode&gt;, which must be one of the following:</p>
<div style="line-height:28px">
<dl style="line-height:28px; margin-top:0.8em; margin-bottom:0.8em"><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
--soft</dt><dd style="line-height:28px">
<p style="line-height:28px; margin-top:0.1em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Does not touch the index file nor the working tree at all (but resets the head to &lt;commit&gt;, just like all modes do). This leaves all your changed files "Changes to be committed", as&nbsp;<span style="line-height:28px; color:navy"><em>git status</em></span>&nbsp;would
 put it.</p>
</dd><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
--mixed</dt><dd style="line-height:28px">
<p style="line-height:28px; margin-top:0.1em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.</p>
</dd><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
--hard</dt><dd style="line-height:28px">
<p style="line-height:28px; margin-top:0.1em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Resets the index and working tree. Any changes to tracked files in the working tree since &lt;commit&gt; are discarded.</p>
</dd><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
--merge</dt><dd style="line-height:28px">
<p style="line-height:28px; margin-top:0.1em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Resets the index and updates the files in the working tree that are different between &lt;commit&gt; and HEAD, but keeps those which are different between the index and working tree (i.e. which have changes which have not been added). If a file that is different
 between &lt;commit&gt; and the index has unstaged changes, reset is aborted.</p>
<div style="line-height:28px">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
In other words, --merge does something like a&nbsp;<span style="line-height:28px; color:navy"><em>git read-tree -u -m &lt;commit&gt;</em></span>, but carries forward unmerged index entries.</p>
</div>
</dd><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
--keep</dt><dd style="line-height:28px">
<p style="line-height:28px; margin-top:0.1em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Resets index entries and updates files in the working tree that are different between &lt;commit&gt; and HEAD. If a file that is different between &lt;commit&gt; and HEAD has local changes, reset is aborted.</p>
</dd></dl>
</div>
</dd></dl>
</div>
<div style="line-height:28px">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
If you want to undo a commit other than the latest on a branch,&nbsp;<a rel="nofollow" href="http://web.mit.edu/~mkgray/project/silk/root/afs/sipb/project/git/git-doc/git-revert.html" style="color:blue; line-height:28px; text-decoration:underline">git-revert(1)</a>&nbsp;is
 your friend.</p>
</div>
</div>
<h2 id="_options" style="line-height:1.3; color:rgb(82,123,189); font-family:sans-serif; margin-top:1.2em; margin-bottom:0.5em; border-bottom-width:2px; border-bottom-style:none; border-bottom-color:silver; padding-top:0.5em; border-top-style:none; border-right-style:none; border-left-style:none"><a name="t1"></a>
OPTIONS</h2>
<div style="line-height:28px; font-family:serif; margin-left:5%">
<div style="line-height:28px">
<dl style="line-height:28px; margin-top:0.8em; margin-bottom:0.8em"><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
-q</dt><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
--quiet</dt><dd style="line-height:28px">
<p style="line-height:28px; margin-top:0.1em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Be quiet, only report errors.</p>
</dd></dl>
</div>
</div>
<h2 id="_examples" style="line-height:1.3; color:rgb(82,123,189); font-family:sans-serif; margin-top:1.2em; margin-bottom:0.5em; border-bottom-width:2px; border-bottom-style:none; border-bottom-color:silver; padding-top:0.5em; border-top-style:none; border-right-style:none; border-left-style:none"><a name="t2"></a>
EXAMPLES</h2>
<div style="line-height:28px; font-family:serif; margin-left:5%">
<div style="line-height:28px">
<dl style="line-height:28px; margin-top:0.8em; margin-bottom:0.8em"><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
Undo add</dt><dd style="line-height:28px">
<div style="line-height:28px; margin-top:0.1em; margin-bottom:1.5em">
<div style="line-height:28px; padding-top:0.5em; padding-right:0.5em; padding-bottom:0.5em; padding-left:0.5em; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:silver; border-right-color:silver; border-bottom-color:silver; border-left-color:silver; background-color:rgb(244,244,244)">
<pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><span style="color:#000080; line-height:23px"></span><pre class="prettyprint" style="line-height:23px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)" name="code"><p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">$ edit                                     </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">1</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> $ git add frotz</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">c filfre</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">c $ mailx                                    </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">2</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> $ git reset                                </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">3</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> $ git pull git</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">:</span><span class="com" style="line-height:23px; color:rgb(136,0,0)">//info.example.com/ nitfol  </span><span style="line-height:23px"><span class="com" style="line-height:23px; color:rgb(136,0,0)">&lt;4&gt;</span></span></p><div class="save_code tracking-ad" data-mod="popu_249"><a href="javascript:;" target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png"></a></div></pre></pre>
</div>
</div>
<div style="line-height:28px">
<ol style="line-height:28px; margin-top:0px; margin-right:0px; margin-bottom:5px; margin-left:40px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; list-style-position:outside">
<li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
You are happily working on something, and find the changes in these files are in good order. You do not want to see them when you run "git diff", because you plan to work on other files and changes with these files are distracting.</p>
</li><li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Somebody asks you to pull, and the changes sounds worthy of merging.</p>
</li><li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
However, you already dirtied the index (i.e. your index does not match the HEAD commit). But you know the pull you are going to make does not affect frotz.c nor filfre.c, so you revert the index changes for these two files. Your changes in working tree remain
 there.</p>
</li><li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Then you can pull and merge, leaving frotz.c and filfre.c changes still in the working tree.</p>
</li></ol>
</div>
</dd><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
Undo a commit and redo</dt><dd style="line-height:28px">
<div style="line-height:28px; margin-top:0.1em; margin-bottom:1.5em">
<div style="line-height:28px; padding-top:0.5em; padding-right:0.5em; padding-bottom:0.5em; padding-left:0.5em; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:silver; border-right-color:silver; border-bottom-color:silver; border-left-color:silver; background-color:rgb(244,244,244)">
<pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><span style="color:#000080; line-height:23px"></span><pre class="prettyprint" style="line-height:23px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)" name="code"><p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">$ git commit </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">...</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> $ git reset </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">soft HEAD</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">^</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">      </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">1</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> $ edit                        </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">2</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> $ git commit </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">a </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">c ORIG_HEAD  </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">3</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span></p><div class="save_code tracking-ad" data-mod="popu_249"><a href="javascript:;" target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png"></a></div></pre></pre>
</div>
</div>
<div style="line-height:28px">
<ol style="line-height:28px; margin-top:0px; margin-right:0px; margin-bottom:5px; margin-left:40px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; list-style-position:outside">
<li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both. Leaves working tree as it was before "reset".</p>
</li><li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Make corrections to working tree files.</p>
</li><li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
"reset" copies the old head to .git/ORIG_HEAD; redo the commit by starting with its log message. If you do not need to edit the message further, you can give -C option instead.</p>
<div style="line-height:28px">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
See also the --amend option to&nbsp;<a rel="nofollow" href="http://web.mit.edu/~mkgray/project/silk/root/afs/sipb/project/git/git-doc/git-commit.html" style="color:blue; line-height:28px; text-decoration:underline">git-commit(1)</a>.</p>
</div>
</li></ol>
</div>
</dd><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
Undo a commit, making it a topic branch</dt><dd style="line-height:28px">
<div style="line-height:28px; margin-top:0.1em; margin-bottom:1.5em">
<div style="line-height:28px; padding-top:0.5em; padding-right:0.5em; padding-bottom:0.5em; padding-left:0.5em; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:silver; border-right-color:silver; border-bottom-color:silver; border-left-color:silver; background-color:rgb(244,244,244)">
<pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><span style="color:#000080; line-height:23px"></span><pre class="prettyprint" style="line-height:23px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)" name="code"><p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">$ git branch topic</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">/</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">wip     </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">1</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> $ git reset </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">hard HEAD</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">~</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">3</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">  </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">2</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> $ git checkout topic</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">/</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">wip   </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">3</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span></p><div class="save_code tracking-ad" data-mod="popu_249" style="display: none;"><a href="javascript:;" target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets_01.png"></a></div></pre></pre>
</div>
</div>
<div style="line-height:28px">
<ol style="line-height:28px; margin-top:0px; margin-right:0px; margin-bottom:5px; margin-left:40px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; list-style-position:outside">
<li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
You have made some commits, but realize they were premature to be in the "master" branch. You want to continue polishing them in a topic branch, so create "topic/wip" branch off of the current HEAD.</p>
</li><li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Rewind the master branch to get rid of those three commits.</p>
</li><li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Switch to "topic/wip" branch and keep working.</p>
</li></ol>
</div>
</dd><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
Undo commits permanently</dt><dd style="line-height:28px">
<div style="line-height:28px; margin-top:0.1em; margin-bottom:1.5em">
<div style="line-height:28px; padding-top:0.5em; padding-right:0.5em; padding-bottom:0.5em; padding-left:0.5em; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:silver; border-right-color:silver; border-bottom-color:silver; border-left-color:silver; background-color:rgb(244,244,244)">
<pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><span style="color:#000080; line-height:23px"></span><pre class="prettyprint" style="line-height:23px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)" name="code"><p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">$ git commit </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">...</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> $ git reset </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">hard HEAD</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">~</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">3</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">   </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">1</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span></p><div class="save_code tracking-ad" data-mod="popu_249"><a href="javascript:;" target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png"></a></div></pre></pre>
</div>
</div>
<div style="line-height:28px">
<ol style="line-height:28px; margin-top:0px; margin-right:0px; margin-bottom:5px; margin-left:40px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; list-style-position:outside">
<li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
The last three commits (HEAD, HEAD^, and HEAD~2) were bad and you do not want to ever see them again. Do&nbsp;<span style="line-height:28px; color:rgb(8,49,148)"><strong>not</strong></span>&nbsp;do this if you have already given these commits to somebody else. (See the
 "RECOVERING FROM UPSTREAM REBASE" section in&nbsp;<a rel="nofollow" href="http://web.mit.edu/~mkgray/project/silk/root/afs/sipb/project/git/git-doc/git-rebase.html" style="color:blue; line-height:28px; text-decoration:underline">git-rebase(1)</a>&nbsp;for the implications
 of doing so.)</p>
</li></ol>
</div>
</dd><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
Undo a merge or pull</dt><dd style="line-height:28px">
<div style="line-height:28px; margin-top:0.1em; margin-bottom:1.5em">
<div style="line-height:28px; padding-top:0.5em; padding-right:0.5em; padding-bottom:0.5em; padding-left:0.5em; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:silver; border-right-color:silver; border-bottom-color:silver; border-left-color:silver; background-color:rgb(244,244,244)">
<pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><span style="color:#000080; line-height:23px"></span><pre class="prettyprint" style="line-height:23px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)" name="code"><p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">$ git pull                         </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">1</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span><span class="typ" style="line-height:23px; color:rgb(102,0,102)">Auto</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">merging nitfol CONFLICT </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">(</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">content</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">):</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span><span class="typ" style="line-height:23px; color:rgb(102,0,102)">Merge</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> conflict </span><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">in</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> nitfol </span><span class="typ" style="line-height:23px; color:rgb(102,0,102)">Automatic</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> merge failed</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">;</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> fix conflicts </span><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">and</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">then</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> commit the result</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> $ git reset </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">hard                 </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">2</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> $ git pull </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> topic</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">/</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">branch          </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">3</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span><span class="typ" style="line-height:23px; color:rgb(102,0,102)">Updating</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">from</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">41223.</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">..</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> to </span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">13134.</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">..</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span><span class="typ" style="line-height:23px; color:rgb(102,0,102)">Fast</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">forward $ git reset </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">hard ORIG_HEAD       </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">4</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span></p><div class="save_code tracking-ad" data-mod="popu_249" style="display: none;"><a href="javascript:;" target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png"></a></div></pre></pre>
</div>
</div>
<div style="line-height:28px">
<ol style="line-height:28px; margin-top:0px; margin-right:0px; margin-bottom:5px; margin-left:40px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; list-style-position:outside">
<li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Try to update from the upstream resulted in a lot of conflicts; you were not ready to spend a lot of time merging right now, so you decide to do that later.</p>
</li><li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
"pull" has not made merge commit, so "git reset --hard" which is a synonym for "git reset --hard HEAD" clears the mess from the index file and the working tree.</p>
</li><li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Merge a topic branch into the current branch, which resulted in a fast-forward.</p>
</li><li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
But you decided that the topic branch is not ready for public consumption yet. "pull" or "merge" always leaves the original tip of the current branch in ORIG_HEAD, so resetting hard to it brings your index file and the working tree back to that state, and resets
 the tip of the branch to that commit.</p>
</li></ol>
</div>
</dd><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
Undo a merge or pull inside a dirty working tree</dt><dd style="line-height:28px">
<div style="line-height:28px; margin-top:0.1em; margin-bottom:1.5em">
<div style="line-height:28px; padding-top:0.5em; padding-right:0.5em; padding-bottom:0.5em; padding-left:0.5em; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:silver; border-right-color:silver; border-bottom-color:silver; border-left-color:silver; background-color:rgb(244,244,244)">
<pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><span style="color:#000080; line-height:23px"></span><pre class="prettyprint" style="line-height:23px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)" name="code"><p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">$ git pull                         </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">1</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span><span class="typ" style="line-height:23px; color:rgb(102,0,102)">Auto</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">merging nitfol </span><span class="typ" style="line-height:23px; color:rgb(102,0,102)">Merge</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> made </span><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">by</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> recursive</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">  nitfol                </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">|</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">   </span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">20</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">+++++----</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">  </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">...</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> $ git reset </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">merge ORIG_HEAD      </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">2</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span></p><div class="save_code tracking-ad" data-mod="popu_249" style="display: none;"><a href="javascript:;" target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets_01.png"></a></div></pre></pre>
</div>
</div>
<div style="line-height:28px">
<ol style="line-height:28px; margin-top:0px; margin-right:0px; margin-bottom:5px; margin-left:40px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; list-style-position:outside">
<li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Even if you may have local modifications in your working tree, you can safely say "git pull" when you know that the change in the other branch does not overlap with them.</p>
</li><li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
After inspecting the result of the merge, you may find that the change in the other branch is unsatisfactory. Running "git reset --hard ORIG_HEAD" will let you go back to where you were, but it will discard your local changes, which you do not want. "git reset
 --merge" keeps your local changes.</p>
</li></ol>
</div>
</dd><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
Interrupted workflow</dt><dd style="line-height:28px">
<div style="line-height:28px; margin-top:0.1em">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Suppose you are interrupted by an urgent fix request while you are in the middle of a large change. The files in your working tree are not in any shape to be committed yet, but you need to get to the other branch for a quick bugfix.</p>
</div>
<div style="line-height:28px; margin-top:1em; margin-bottom:1.5em">
<div style="line-height:28px; padding-top:0.5em; padding-right:0.5em; padding-bottom:0.5em; padding-left:0.5em; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:silver; border-right-color:silver; border-bottom-color:silver; border-left-color:silver; background-color:rgb(244,244,244)">
<pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><span style="color:#000080; line-height:23px"></span><pre class="prettyprint" style="line-height:23px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)" name="code"><p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">$ git checkout feature </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">;</span><span class="com" style="line-height:23px; color:rgb(136,0,0)"># you were working in "feature" branch and $ work work work       ;# got interrupted $ git commit -a -m "snapshot WIP"                 </span><span style="line-height:23px"><span class="com" style="line-height:23px; color:rgb(136,0,0)">&lt;1&gt;</span></span><span class="com" style="line-height:23px; color:rgb(136,0,0)"> $ git checkout master $ fix fix fix $ git commit ;# commit with real log $ git checkout feature $ git reset --soft HEAD^ ;# go back to WIP state  </span><span style="line-height:23px"><span class="com" style="line-height:23px; color:rgb(136,0,0)">&lt;2&gt;</span></span><span class="com" style="line-height:23px; color:rgb(136,0,0)"> $ git reset                                       </span><span style="line-height:23px"><span class="com" style="line-height:23px; color:rgb(136,0,0)">&lt;3&gt;</span></span></p><div class="save_code tracking-ad" data-mod="popu_249" style="display: none;"><a href="javascript:;" target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png"></a></div></pre></pre>
</div>
</div>
<div style="line-height:28px">
<ol style="line-height:28px; margin-top:0px; margin-right:0px; margin-bottom:5px; margin-left:40px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; list-style-position:outside">
<li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
This commit will get blown away so a throw-away log message is OK.</p>
</li><li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
This removes the&nbsp;<span style="line-height:28px; color:navy"><em>WIP</em></span>&nbsp;commit from the commit history, and sets your working tree to the state just before you made that snapshot.</p>
</li><li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
At this point the index file still has all the WIP changes you committed as&nbsp;<span style="line-height:28px; color:navy"><em>snapshot WIP</em></span>. This updates the index to show your WIP files as uncommitted.</p>
<div style="line-height:28px">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
See also&nbsp;<a rel="nofollow" href="http://web.mit.edu/~mkgray/project/silk/root/afs/sipb/project/git/git-doc/git-stash.html" style="color:blue; line-height:28px; text-decoration:underline">git-stash(1)</a>.</p>
</div>
</li></ol>
</div>
</dd><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
Reset a single file in the index</dt><dd style="line-height:28px">
<div style="line-height:28px; margin-top:0.1em">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Suppose you have added a file to your index, but later decide you do not want to add it to your commit. You can remove the file from the index while keeping your changes with git reset.</p>
</div>
<div style="line-height:28px; margin-top:1em; margin-bottom:1.5em">
<div style="line-height:28px; padding-top:0.5em; padding-right:0.5em; padding-bottom:0.5em; padding-left:0.5em; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:silver; border-right-color:silver; border-bottom-color:silver; border-left-color:silver; background-color:rgb(244,244,244)">
<pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><span style="color:#000080; line-height:23px"></span><pre class="prettyprint" style="line-height:23px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)" name="code"><p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">$ git reset </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> frotz</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">c                      </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">1</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> $ git commit </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">m </span><span class="str" style="line-height:23px; color:rgb(0,136,0)">"Commit files in index"</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">     </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">2</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> $ git add frotz</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">c                           </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">3</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span></p><div class="save_code tracking-ad" data-mod="popu_249"><a href="javascript:;" target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png"></a></div></pre></pre>
</div>
</div>
<div style="line-height:28px">
<ol style="line-height:28px; margin-top:0px; margin-right:0px; margin-bottom:5px; margin-left:40px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; list-style-position:outside">
<li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
This removes the file from the index while keeping it in the working directory.</p>
</li><li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
This commits all other changes in the index.</p>
</li><li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Adds the file to the index again.</p>
</li></ol>
</div>
</dd><dt style="line-height:28px; margin-top:0.5em; margin-bottom:0px; font-style:normal; color:navy">
Keep changes in working tree while discarding some previous commits</dt><dd style="line-height:28px">
<div style="line-height:28px; margin-top:0.1em">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
Suppose you are working on something and you commit it, and then you continue working a bit more, but now you think that what you have in your working tree should be in another branch that has nothing to do with what you committed previously. You can start
 a new branch and reset it while keeping the changes in your working tree.</p>
</div>
<div style="line-height:28px; margin-top:1em; margin-bottom:1.5em">
<div style="line-height:28px; padding-top:0.5em; padding-right:0.5em; padding-bottom:0.5em; padding-left:0.5em; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:silver; border-right-color:silver; border-bottom-color:silver; border-left-color:silver; background-color:rgb(244,244,244)">
<pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><span style="color:#000080; line-height:23px"></span><pre class="prettyprint" style="line-height:23px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)" name="code"><p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">$ git tag start $ git checkout </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">b branch1 $ edit $ git commit </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">...</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">                            </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">1</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> $ edit $ git checkout </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">b branch2                   </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">2</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> $ git reset </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">keep start                    </span><span style="line-height:23px"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&lt;</span><span class="lit" style="line-height:23px; color:rgb(0,102,102)">3</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">&gt;</span></span></p><div class="save_code tracking-ad" data-mod="popu_249"><a href="javascript:;" target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png"></a></div></pre></pre>
</div>
</div>
<div style="line-height:28px">
<ol style="line-height:28px; margin-top:0px; margin-right:0px; margin-bottom:5px; margin-left:40px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; list-style-position:outside">
<li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
This commits your first edits in branch1.</p>
</li><li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
In the ideal world, you could have realized that the earlier commit did not belong to the new topic when you created and switched to branch2 (i.e. "git checkout -b branch2 start"), but nobody is perfect.</p>
</li><li style="line-height:28px">
<p style="line-height:28px; margin-top:0px; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
But you can use "reset --keep" to remove the unwanted commit after you switched to "branch2".</p>
</li></ol>
</div>
</dd></dl>
</div>
</div>
<h2 id="_discussion" style="line-height:1.3; color:rgb(82,123,189); font-family:sans-serif; margin-top:1.2em; margin-bottom:0.5em; border-bottom-width:2px; border-bottom-style:none; border-bottom-color:silver; padding-top:0.5em; border-top-style:none; border-right-style:none; border-left-style:none"><a name="t3"></a>
DISCUSSION</h2>
<div style="line-height:28px; font-family:serif; margin-left:5%">
<div style="line-height:28px">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
The tables below show what happens when running:</p>
</div>
<div style="line-height:28px; margin-top:1em; margin-bottom:1.5em">
<div style="line-height:28px; padding-top:0.5em; padding-right:0.5em; padding-bottom:0.5em; padding-left:0.5em; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:silver; border-right-color:silver; border-bottom-color:silver; border-left-color:silver; background-color:rgb(244,244,244)">
<pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><tt style="line-height:23px; color:navy">git reset --option target</tt></pre>
</div>
</div>
<div style="line-height:28px">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
to reset the HEAD to another commit (<tt style="line-height:23px; color:navy">target</tt>) with the different reset options depending on the state of the files.</p>
</div>
<div style="line-height:28px">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
In these tables, A, B, C and D are some different states of a file. For example, the first line of the first table means that if a file is in state A in the working tree, in state B in the index, in state C in HEAD and in state D in the target, then "git reset
 --soft target" will leave the file in the working tree in state A and in the index in state B. It resets (i.e. moves) the HEAD (i.e. the tip of the current branch, if you are on one) to "target" (which has the file in state D).</p>
</div>
<div style="line-height:28px; margin-top:1em; margin-bottom:1.5em">
<div style="line-height:28px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px">
<pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><span style="color:#000080; line-height:23px"></span><pre class="prettyprint" style="line-height:23px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)" name="code"><p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"></p><div style="line-height:23px; margin-top:1em; margin-bottom:1.5em"><div style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px"><pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><tt style="line-height:23px; color:navy"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">working index HEAD target         working index HEAD </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">----------------------------------------------------</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">  A       B     C    D     </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">soft   A       B     D                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">mixed  A       D     D                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">hard   D       D     D                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">merge </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">(</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">disallowed</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">)</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">keep  </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">(</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">disallowed</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">)</span></tt></pre></div></div><div style="line-height:23px; margin-top:1em; margin-bottom:1.5em"><div style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px"><pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><tt style="line-height:23px; color:navy"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">working index HEAD target         working index HEAD </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">----------------------------------------------------</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">  A       B     C    C     </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">soft   A       B     C                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">mixed  A       C     C                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">hard   C       C     C                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">merge </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">(</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">disallowed</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">)</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">keep   A       C     </span><span class="typ" style="line-height:23px; color:rgb(102,0,102)">C</span></tt></pre></div></div><div style="line-height:23px; margin-top:1em; margin-bottom:1.5em"><div style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px"><pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><tt style="line-height:23px; color:navy"><span class="typ" style="line-height:23px; color:rgb(102,0,102)">working</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> index HEAD target         working index HEAD </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">----------------------------------------------------</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">  B       B     C    D     </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">soft   B       B     D                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">mixed  B       D     D                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">hard   D       D     D                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">merge  D       D     D                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">keep  </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">(</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">disallowed</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">)</span></tt></pre></div></div><div style="line-height:23px; margin-top:1em; margin-bottom:1.5em"><div style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px"><pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><tt style="line-height:23px; color:navy"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">working index HEAD target         working index HEAD </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">----------------------------------------------------</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">  B       B     C    C     </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">soft   B       B     C                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">mixed  B       C     C                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">hard   C       C     C                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">merge  C       C     C                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">keep   B       C     </span><span class="typ" style="line-height:23px; color:rgb(102,0,102)">C</span></tt></pre></div></div><div style="line-height:23px; margin-top:1em; margin-bottom:1.5em"><div style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px"><pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><tt style="line-height:23px; color:navy"><span class="typ" style="line-height:23px; color:rgb(102,0,102)">working</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> index HEAD target         working index HEAD </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">----------------------------------------------------</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">  B       C     C    D     </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">soft   B       C     D                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">mixed  B       D     D                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">hard   D       D     D                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">merge </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">(</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">disallowed</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">)</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">keep  </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">(</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">disallowed</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">)</span></tt></pre></div></div><div style="line-height:23px; margin-top:1em; margin-bottom:1.5em"><div style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px"><pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><tt style="line-height:23px; color:navy"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">working index HEAD target         working index HEAD </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">----------------------------------------------------</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">  B       C     C    C     </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">soft   B       C     C                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">mixed  B       C     C                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">hard   C       C     C                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">merge  B       C     C                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">keep   B       C     C</span></tt></pre></div></div><p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"></p><div class="save_code tracking-ad" data-mod="popu_249" style="display: none;"><a href="javascript:;" target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png"></a></div></pre></pre>
</div>
</div>
<div style="line-height:28px">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
"reset --merge" is meant to be used when resetting out of a conflicted merge. Any mergy operation guarantees that the working tree file that is involved in the merge does not have local change wrt the index before it starts, and that it writes the result out
 to the working tree. So if we see some difference between the index and the target and also between the index and the working tree, then it means that we are not resetting out from a state that a mergy operation left after failing with a conflict. That is
 why we disallow --merge option in this case.</p>
</div>
<div style="line-height:28px">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
"reset --keep" is meant to be used when removing some of the last commits in the current branch while keeping changes in the working tree. If there could be conflicts between the changes in the commit we want to remove and the changes in the working tree we
 want to keep, the reset is disallowed. That’s why it is disallowed if there are both changes between the working tree and HEAD, and between HEAD and the target. To be safe, it is also disallowed when there are unmerged entries.</p>
</div>
<div style="line-height:28px">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
The following tables show what happens when there are unmerged entries:</p>
</div>
<div style="line-height:28px; margin-top:1em; margin-bottom:1.5em">
<div style="line-height:28px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px">
<pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><span style="color:#000080; line-height:23px"></span><pre class="prettyprint" style="line-height:23px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)" name="code"><p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"></p><div style="line-height:23px; margin-top:1em; margin-bottom:1.5em"><div style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px"><pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><tt style="line-height:23px; color:navy"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">working index HEAD target         working index HEAD </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">----------------------------------------------------</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">  X       U     A    B     </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">soft  </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">(</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">disallowed</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">)</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">mixed  X       B     B                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">hard   B       B     B                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">merge  B       B     B                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">keep  </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">(</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">disallowed</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">)</span></tt></pre></div></div><div style="line-height:23px; margin-top:1em; margin-bottom:1.5em"><div style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px"><pre style="line-height:23px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-bottom:0px"><tt style="line-height:23px; color:navy"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">working index HEAD target         working index HEAD </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">----------------------------------------------------</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">  X       U     A    A     </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">soft  </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">(</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">disallowed</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">)</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">mixed  X       A     A                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">hard   A       A     A                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">merge  A       A     A                           </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">keep  </span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">(</span><span class="pln" style="line-height:23px; color:rgb(0,0,0)">disallowed</span><span class="pun" style="line-height:23px; color:rgb(102,102,0)">)</span></tt></pre></div></div><p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"></p><div class="save_code tracking-ad" data-mod="popu_249" style="display: none;"><a href="javascript:;" target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png"></a></div></pre></pre>
</div>
</div>
<div style="line-height:28px">
<p style="line-height:28px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px">
X means any state and U means an unmerged index.</p>
</div>
</div>
</div>
<div style="line-height:25px">
<div style="line-height:25px">结束<br style="line-height:25px">
</div>
</div>
</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="1490750491010">
<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 -->

   <link rel="stylesheet" href="http://static.blog.csdn.net/css/blog_detail.css">

    
<!--172.16.140.11-->

<!-- Baidu Button BEGIN -->
<script type="text/javascript" id="bdshare_js" data="type=tools&amp;uid=1536434" src="http://bdimg.share.baidu.com/static/js/bds_s_v2.js?cdnversion=414098"></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 -->

<script type="text/javascript">
    var fromjs = $("#fromjs");
    if (fromjs.length > 0) {
            $("#fromjs .markdown_views pre").addClass("prettyprint");
            prettyPrint();

            $('pre.prettyprint code').each(function () {
                var lines = $(this).text().split('\n').length;
                var $numbering = $('<ul/>').addClass('pre-numbering').hide();
                $(this).addClass('has-numbering').parent().append($numbering);
                for (i = 1; i <= lines; i++) {
                    $numbering.append($('<li/>').text(i));
                };
                $numbering.fadeIn(1700);
            });

            $('.pre-numbering li').css("color", "#999");
        }

    

</script>

 


        <div id="digg" articleid="7664464">
            <dl id="btnDigg" class="digg digg_enable" οnclick="btndigga();">
               
                 <dt>顶</dt>
                <dd>2</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">&nbsp;</a>   </div>
    <div class="tracking-ad" data-mod="popu_223"> <a href="javascript:void(0);" target="_blank">&nbsp;</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='/hudashi/article/details/7664460';">上一篇</span><a href="/hudashi/article/details/7664460" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_shangyipian'])">git revert和git reset的区别</a></li>
                <li class="next_article"><span οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_xiayipian']);location.href='/hudashi/article/details/7664468';">下一篇</span><a href="/hudashi/article/details/7664468" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_xiayipian'])">git tag简介</a></li>
    </ul>

    <div style="clear:both; height:10px;"></div>


        <div class="similar_article" style="">
                <h4>我的同类文章</h4>
                <div class="similar_c" style="margin:20px 0px 0px 0px">
                    <div class="similar_c_t">
                                <label class="similar_cur">
                                    <span style="cursor:pointer" οnclick="GetCategoryArticles('1122124','hudashi','foot','7664464');">版本控制<em>(50)</em></span>
                                </label>
                    </div>
                   
                    <div class="similar_wrap tracking-ad" data-mod="popu_141" style="max-height:195px;">
                        <a href="http://blog.csdn.net" style="display:none" target="_blank">http://blog.csdn.net</a>
                        <ul class="similar_list fl"><li><em>•</em><a href="http://blog.csdn.net/hudashi/article/details/54668359" id="foot_aritcle_54668359undefined8163539562230591" target="_blank" title="如何搭建开源code review gerrit服务器">如何搭建开源code review gerrit服务器</a><span>2017-01-22</span><label><i>阅读</i><b>194</b></label></li> <li><em>•</em><a href="http://blog.csdn.net/hudashi/article/details/53259646" id="foot_aritcle_53259646undefined568648408349666" target="_blank" title="no matching key exchange method found. Their offer: diffie-hellman-group1-sha1">no matching key exchange method found. Their offer: diffie-hellman-group1-sha1</a><span>2016-11-21</span><label><i>阅读</i><b>344</b></label></li> <li><em>•</em><a href="http://blog.csdn.net/hudashi/article/details/51782560" id="foot_aritcle_51782560undefined1781840968101548" target="_blank" title=".gitignore简介">.gitignore简介</a><span>2016-06-29</span><label><i>阅读</i><b>316</b></label></li> <li><em>•</em><a href="http://blog.csdn.net/hudashi/article/details/45080721" id="foot_aritcle_45080721undefined43357675341853297" target="_blank" title="git status简介">git status简介</a><span>2015-04-16</span><label><i>阅读</i><b>21778</b></label></li> <li><em>•</em><a href="http://blog.csdn.net/hudashi/article/details/45079229" id="foot_aritcle_45079229undefined7612930096566176" target="_blank" title="Forking工作流">Forking工作流</a><span>2015-04-16</span><label><i>阅读</i><b>953</b></label></li> <li><em>•</em><a href="http://blog.csdn.net/hudashi/article/details/45079031" id="foot_aritcle_45079031undefined36688614465474445" target="_blank" title="Git功能分支工作流">Git功能分支工作流</a><span>2015-04-16</span><label><i>阅读</i><b>1131</b></label></li> </ul>

                        <ul class="similar_list fr"><li><em>•</em><a href="http://blog.csdn.net/hudashi/article/details/53789368" id="foot_aritcle_53789368undefined5467647374443466" target="_blank" title="关于git的ssh-key:解决本地多个ssh-key的问题">关于git的ssh-key:解决本地多个ssh-key的问题</a><span>2016-12-21</span><label><i>阅读</i><b>151</b></label></li> <li><em>•</em><a href="http://blog.csdn.net/hudashi/article/details/53130689" id="foot_aritcle_53130689undefined08858432518413017" target="_blank" title="【Gerrit】添加git工程到gerrit服务器">【Gerrit】添加git工程到gerrit服务器</a><span>2016-11-11</span><label><i>阅读</i><b>505</b></label></li> <li><em>•</em><a href="http://blog.csdn.net/hudashi/article/details/46325387" id="foot_aritcle_46325387undefined13556063817666053" target="_blank" title="beyond compare 与git diff整合">beyond compare 与git diff整合</a><span>2015-06-02</span><label><i>阅读</i><b>3077</b></label></li> <li><em>•</em><a href="http://blog.csdn.net/hudashi/article/details/45079265" id="foot_aritcle_45079265undefined36783142404098557" target="_blank" title="Pull Request工作流">Pull Request工作流</a><span>2015-04-16</span><label><i>阅读</i><b>1335</b></label></li> <li><em>•</em><a href="http://blog.csdn.net/hudashi/article/details/45079103" id="foot_aritcle_45079103undefined763158695467797" target="_blank" title="Gitflow工作流">Gitflow工作流</a><span>2015-04-16</span><label><i>阅读</i><b>1211</b></label></li> </ul>
                    <a href="http://blog.csdn.net/hudashi/article/category/1122124" class="MoreArticle">更多文章</a></div>
                </div>
            </div>    
    <script type="text/javascript">
        $(function () {
            GetCategoryArticles('1122124', 'hudashi','foot','7664464');
        });
    </script>
      
</div>

     <div>
             <div style="width: 960px; height: 90px;" class="J_adv" data-view="true" data-mod="ad_popu_206" data-mtp="43" data-order="114" data-con="ad_content_1901"><script src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><ins class="adsbygoogle" style="display:inline-block;width:960px;height:90px" data-ad-client="ca-pub-8990951720398508" data-ad-slot="8267689356/3776917242" data-adsbygoogle-status="done"><ins id="aswift_0_expand" style="display:inline-table;border:none;height:90px;margin:0;padding:0;position:relative;visibility:visible;width:960px;background-color:transparent"><ins id="aswift_0_anchor" style="display:block;border:none;height:90px;margin:0;padding:0;position:relative;visibility:visible;width:960px;background-color:transparent"><iframe marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" οnlοad="var i=this.id,s=window.google_iframe_oncopy,H=s&amp;&amp;s.handlers,h=H&amp;&amp;H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&amp;&amp;d&amp;&amp;(!d.body||!d.body.firstChild)){if(h.call){setTimeout(h,0)}else if(h.match){try{h=s.upd(h,i)}catch(e){}w.location.replace(h)}}" id="aswift_0" name="aswift_0" style="left:0;position:absolute;top:0;" frameborder="0" height="90" width="960"></iframe></ins></ins></ins><script>(adsbygoogle=window.adsbygoogle || []).push({});</script></div>
    </div>

<div id="suggest">

</div>
         <script language="javascript" type="text/javascript">     
             $(function(){
                 $.get("/hudashi/svc/GetSuggestContent/7664464",function(data){
                     $("#suggest").html(data);
                 });     
             });             
         </script>  


<style>
.blog-ass-articl dd {
color: #369;
width: 99%; /*修改行*/
float: left;
overflow: hidden;
font: normal normal 12px/23px "SimSun";
height: 23px;
margin: 0;
padding: 0 0 0 10px;
margin-right: 30px;
background: url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px;
}
</style>

 <link rel="stylesheet" href="http://static.blog.csdn.net/css/replace.css">

<div id="relate" data-mod="popu_218" class="tracking-ad" style="display: block;">
        <div class="relate_t">
            <h3><span>参考知识库</span></h3>
        </div>
        <div class="relate_c"><dl class="relate_list"><dt><a target="_blank" href="http://lib.csdn.net/base/go"><img src="http://img.knowledge.csdn.net/upload/base/1471395508721_721.jpg" alt="img"></a></dt><dd><h4><a target="_blank" href="http://lib.csdn.net/base/go">Go知识库</a></h4><p><label><span>2089</span><em>关注</em><i>|</i><span>919</span><em>收录</em></label></p></dd></dl><dl class="relate_list"><dt><a target="_blank" href="http://lib.csdn.net/base/scala"><img src="http://img.knowledge.csdn.net/upload/base/1469086540236_236.jpg" alt="img"></a></dt><dd><h4><a target="_blank" href="http://lib.csdn.net/base/scala">Scala知识库</a></h4><p><label><span>1400</span><em>关注</em><i>|</i><span>680</span><em>收录</em></label></p></dd></dl><dl class="relate_list"><dt><a target="_blank" href="http://lib.csdn.net/base/git"><img src="http://img.knowledge.csdn.net/upload/base/1460535308634_634.jpg" alt="img"></a></dt><dd><h4><a target="_blank" href="http://lib.csdn.net/base/git">Git知识库</a></h4><p><label><span>6245</span><em>关注</em><i>|</i><span>612</span><em>收录</em></label></p></dd></dl></div>
</div>
 

<dl class="blog-ass-articl" id="res-relatived">
    <div class="embody embody_b" id="libkeyparent" style="display:none">
            <span class="embody_t">更多资料请参考:</span>
            <div class="embody_c" id="libkey"></div>
    </div>


     <dt><span>猜你在找</span></dt>    


   


    <div id="adCollege" style="width: 42%;float: left;">
        <script src="http://csdnimg.cn/jobreco/job_reco.js" type="text/javascript"></script>
        <script type="text/javascript">
            csdn.position.showEdu({
                sourceType: "blog",
                searchType: "detail",
                searchKey: "7664464",
                username: "flyflyflyfly123",
                recordcount: "5",
                containerId: "adCollege" //容器DIV的id。
            });
            
            setEduLoc();

            function setEduLoc() {               
                var edus = $("#adCollege div dd a");
                if (edus.length == 0) {
                    setTimeout(function () {
                        setEduLoc();
                    }, 500);
                }
                else {
                    var eduLoc = "?ref=blog&loc=0";
                    $.each(edus, function (index,item) {
                        var href = $(this).attr("href") + eduLoc;
                        $(this).attr("href", href);
                    });
                }
            }

        </script>
    <div class="tracking-ad" data-mod="popu_84"><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px; white-space: nowrap;"><a href="http://edu.csdn.net/course/detail/2997?ref=blog&amp;loc=0" title="ArcGIS for javascript 项目实战(环境监测系统)" strategy="v4:content" target="_blank">ArcGIS for javascript 项目实战(环境监测系统)</a></dd><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px; white-space: nowrap;"><a href="http://edu.csdn.net/course/detail/1071?ref=blog&amp;loc=0" title="ArcGIS for JavaScript" strategy="v4:content" target="_blank">ArcGIS for JavaScript</a></dd><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px; white-space: nowrap;"><a href="http://edu.csdn.net/course/detail/3708?ref=blog&amp;loc=0" title="从零开始学习mac系统视频录制编辑软件Camtasia For Mac视频课程" strategy="v4:content" target="_blank">从零开始学习mac系统视频录制编辑软件Camtasia For Mac视频课程</a></dd><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px; white-space: nowrap;"><a href="http://edu.csdn.net/course/detail/3639?ref=blog&amp;loc=0" title="Android开发高级组件与框架——Git与Linux" strategy="v4:content" target="_blank">Android开发高级组件与框架——Git与Linux</a></dd><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px; white-space: nowrap;"><a href="http://edu.csdn.net/course/detail/3161?ref=blog&amp;loc=0" title="I2C总线和触摸屏驱动移植实战-linux驱动开发第9部分" strategy="v4:content" target="_blank">I2C总线和触摸屏驱动移植实战-linux驱动开发第9部分</a></dd></div></div>  

    
     <div id="res" data-mod="popu_36" class="tracking-ad" style="width: 42%; float: left; margin-right: 30px; display: block;"><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px;"><a href="http://blog.csdn.net/Guofengpu/article/details/52058014" title="VLC框架分析" strategy="SearchAlgorithm" target="_blank">VLC框架分析</a></dd><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px;"><a href="http://blog.csdn.net/mic_Nirvana/article/details/21554655" title="GitHub详细教程" strategy="SearchAlgorithm" target="_blank">GitHub详细教程</a></dd><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px;"><a href="http://blog.csdn.net/pressman/article/details/385562" title="AIX常见问题整理" strategy="SearchAlgorithm" target="_blank">AIX常见问题整理</a></dd><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px;"><a href="http://blog.csdn.net/Nikolai/article/details/914591" title="转载AIX 常见问题整理" strategy="SearchAlgorithm" target="_blank">转载AIX 常见问题整理</a></dd><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px;"><a href="http://blog.csdn.net/u013510614/article/details/40649309" title="GitHub详细教程" strategy="SearchAlgorithm" target="_blank">GitHub详细教程</a></dd></div>
   
</dl>


<script type="text/javascript">
    $(function () {
        setTimeout(function () {
            var searchtitletags = 'git reset简介' + ',' + $("#tags").html();
            searchService({
                index: 'blog',
                query: searchtitletags,
                from: 5,
                size: 5,
                appendTo: '#res',
                url: 'recommend',
                his: 2,
                client: "blog_cf_enhance",
                tmpl: '<dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px;"><a href="#{ url }" title="#{ title }" strategy="#{ strategy }">#{ title }</a></dd>'
            });
        }, 500);
    });    

 </script>  


    <div id="ad_cen">        
                      <div style="width: 960px; height: 90px;" class="J_adv" data-view="true" data-mod="ad_popu_199" data-mtp="43" data-order="114" data-con="ad_content_1843"><script src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><ins class="adsbygoogle" style="display:inline-block;width:960px;height:90px" data-ad-client="ca-pub-8990951720398508" data-ad-slot="8267689356/3115746762" data-adsbygoogle-status="done"><ins id="aswift_1_expand" style="display:inline-table;border:none;height:90px;margin:0;padding:0;position:relative;visibility:visible;width:960px;background-color:transparent"><ins id="aswift_1_anchor" style="display:block;border:none;height:90px;margin:0;padding:0;position:relative;visibility:visible;width:960px;background-color:transparent"><iframe marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" οnlοad="var i=this.id,s=window.google_iframe_oncopy,H=s&amp;&amp;s.handlers,h=H&amp;&amp;H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&amp;&amp;d&amp;&amp;(!d.body||!d.body.firstChild)){if(h.call){setTimeout(h,0)}else if(h.match){try{h=s.upd(h,i)}catch(e){}w.location.replace(h)}}" id="aswift_1" name="aswift_1" style="left:0;position:absolute;top:0;" frameborder="0" height="90" width="960"></iframe></ins></ins></ins><script>(adsbygoogle=window.adsbygoogle || []).push({});</script></div>
    </div>  

    <!-- 广告位开始 -->
    <div style="" class="J_adv" data-view="true" data-mod="ad_popu_72" data-mtp="62" data-order="40" data-con="ad_content_2072"><script id="popuLayer_js_q" src="http://ads.csdn.net/js/popuLayer.js" defer="" type="text/javascript"></script><div id="layerd" style="position: fixed; bottom: 0px; right: 0px; line-height: 0px; z-index: 1000; width: 300px; height: 278px; display: none;"><div class="J_close layer_close" style="display:;background-color:#efefef;padding:0px;color:#333;font:12px/24px Helvetica,Tahoma,Arial,sans-serif;text-align:right;">关闭</div><!-- 广告占位容器 --><div id="cpro_u2895327"><iframe id="iframeu2895327_0" src="http://pos.baidu.com/ycmm?rdid=2895327&amp;dc=3&amp;di=u2895327&amp;dri=0&amp;dis=0&amp;dai=1&amp;ps=642x963&amp;dcb=___adblockplus&amp;dtm=HTML_POST&amp;dvi=0.0&amp;dci=-1&amp;dpt=none&amp;tsr=0&amp;tpr=1490750491111&amp;ti=git%20reset%E7%AE%80%E4%BB%8B%20-%20Robin%20Hu%E7%9A%84%E4%B8%93%E6%A0%8F%20-%20%E5%8D%9A%E5%AE%A2%E9%A2%91%E9%81%93%20-%20CSDN.NET&amp;ari=2&amp;dbv=0&amp;drs=3&amp;pcs=1263x896&amp;pss=1265x14922&amp;cfv=25&amp;cpl=1&amp;chi=2&amp;cce=true&amp;cec=UTF-8&amp;tlm=1490750491&amp;rw=913&amp;ltu=http%3A%2F%2Fblog.csdn.net%2Fhudashi%2Farticle%2Fdetails%2F7664464%2F&amp;ecd=1&amp;uc=1280x984&amp;pis=-1x-1&amp;ccd=24&amp;cja=false&amp;cmi=2&amp;col=en-GB&amp;cdo=-1&amp;sr=1280x1024&amp;tcn=1490750491&amp;qn=67962a4dfe8b50ff&amp;tt=1490750491094.20.20.21" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" style="border:0;vertical-align:bottom;margin:0;width:300px;height:250px" allowtransparency="true" align="center,center" frameborder="0" height="250" width="300"></iframe></div></div><script>  document.getElementById('popuLayer_js_q').οnlοad=function(){      var styObjd=styObj={width:'300px','height':parseInt(250)+28};window.CSDN.Layer.PopuLayer('#layerd',{storageName:'layerd',styleObj:styObjd,total:50,expoire:1000*60});  }</script><!-- 投放代码 --><script type="text/javascript">   /*服务器频道首页置顶Banner960*90,创建于2014-7-3*/    (window.cproArray = window.cproArray || []).push({        id: 'u2895327'      });  </script>  <script src="http://cpro.baidustatic.com/cpro/ui/c.js" type="text/javascript"></script></div>
    <!-- 广告位结束 -->

<div class="comment_class">
    <div id="comment_title" class="panel_head">
        <span class="see_comment">查看评论</span><a name="comments"></a></div>
    <div id="comment_list"><dl class="comment_item comment_topic" id="comment_item_6425677"><dt class="comment_head" floor="4">4楼 <span class="user"><a class="username" href="/WuXiaoQuan824212" target="_blank">吴小全</a> <span class="ptime">2016-11-23 11:14发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6425677" username="WuXiaoQuan824212"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/WuXiaoQuan824212" target="_blank"><img src="http://avatar.csdn.net/2/9/4/3_wuxiaoquan824212.jpg" height="40" width="40"></a></dd><dd class="comment_body">很好的介绍</dd></dl><dl class="comment_item comment_topic" id="comment_item_3142481"><dt class="comment_head" floor="3">3楼 <span class="user"><a class="username" href="/Hello_ok_google" target="_blank">清风乐逍遥</a> <span class="ptime">2013-11-13 16:44发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="3142481" username="Hello_ok_google"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/Hello_ok_google" target="_blank"><img src="http://avatar.csdn.net/B/F/C/3_hello_ok_google.jpg" height="40" width="40"></a></dd><dd class="comment_body">你好,我刚看了你的常用示例A) 回滚add操纵 ,如果对合并没有相同的数据的话,我觉得是没有必要的吧,我没有执行git reset,但运行了git pull ,合并后git log 发现对HEAD没有影响,但你说的对index搞乱了,只的是什么啊,我这点不是很明白。</dd></dl><dl class="comment_item comment_topic" id="comment_item_2964883"><dt class="comment_head" floor="2">2楼 <span class="user"><a class="username" href="/hiveer" target="_blank">hiveer</a> <span class="ptime">2013-10-08 14:35发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="2964883" username="hiveer"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/hiveer" target="_blank"><img src="http://avatar.csdn.net/4/9/C/3_hiveer.jpg" height="40" width="40"></a></dd><dd class="comment_body">前面的能看懂 后面点的感觉比较吃力 很好的文章</dd></dl><dl class="comment_item comment_topic" id="comment_item_2709575"><dt class="comment_head" floor="1">1楼 <span class="user"><a class="username" href="/j236027367" target="_blank">洛莫I</a> <span class="ptime">2013-07-04 19:15发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="2709575" username="j236027367"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/j236027367" target="_blank"><img src="http://avatar.csdn.net/6/C/9/3_j236027367.jpg" height="40" width="40"></a></dd><dd class="comment_body">很有用哦,谢谢</dd></dl><div class="clear"></div></div>
    <div id="comment_bar" style="display: none;">
    </div>
    <div id="comment_form"><a name="commentbox"></a><a name="reply"></a><a name="quote"></a><form action="/hudashi/comment/submit?id=7664464" method="post" οnsubmit="return subform(this);"><div class="commentform"><div class="panel_head">发表评论</div><ul><li class="left">用 户 名:</li><li class="right">flyflyflyfly123</li></ul><ul><li class="left">评论内容:</li><li class="right" style="position:relative;"><div id="ubbtools"><a href="#insertcode" code="code"><img src="http://static.blog.csdn.net/images/ubb/code.gif" alt="插入代码" title="插入代码" border="0"></a></div><div id="lang_list" style="position: absolute; top: 28px; left: 0px; display: none;"><a class="long_name" href="#html">HTML/XML</a><a class="long_name" href="#objc">objective-c</a><a class="zhong_name" href="#delphi">Delphi</a><a class="zhong_name" href="#ruby">Ruby</a><a href="#php">PHP</a><a class="duan_name" href="#csharp">C#</a><a style=" border-right: none;" class="duan_name" href="#cpp">C++</a><a style=" border-bottom:none;" class="long_name" href="#javascript">JavaScript</a><a style=" border-bottom:none;" class="long_name" href="#vb">Visual Basic</a><a style=" border-bottom:none;" class="zhong_name" href="#python">Python</a><a style=" border-bottom:none;" class="zhong_name" href="#java">Java</a><a style="border-bottom:none;" class="duan_name" href="#css">CSS</a><a style="border-bottom:none;" class="duan_name" href="#sql">SQL</a><a style="border:none;" class="duan_name" href="#plain">其它</a></div><textarea class="comment_content" name="comment_content" id="comment_content" style="width: 400px; height: 200px;"></textarea></li></ul><ul><input id="comment_replyId" name="comment_replyId" type="hidden"><input id="comment_userId" name="comment_userId" value="521203" type="hidden"><input id="commentId" name="commentId" value="" type="hidden"><input class="comment_btn" value="提交" type="submit">&nbsp;&nbsp;<span id="tip_comment" style="color: Red; display: none;"></span></ul></div></form></div>
    <div class="announce">
        * 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场<a name="reply"></a><a name="quote"></a></div>
</div>

<script type="text/javascript">
    var fileName = '7664464';
    var commentscount = 5;
    var islock = false
</script>
<script type="text/javascript" src="http://static.blog.csdn.net/scripts/comment.js"></script>
    <div id="ad_bot">
    </div>
<div id="report_dialog">
</div>

<div id="d-top" style="bottom:60px;">

        <a id="quick-reply" class="btn btn-top q-reply" title="快速回复" style="display:none;">
            <img src="http://static.blog.csdn.net/images/blog-icon-reply.png" alt="快速回复">
        </a>    
    <a id="d-top-a" class="btn btn-top backtop" style="display: none;" title="返回顶部" οnclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_huidaodingbu'])">         
         <img src="http://static.blog.csdn.net/images/top.png" alt="TOP">
    </a>
</div>
<script type="text/javascript">
    $(function ()
    {
        $("#ad_frm_0").height("90px");
        
        setTimeout(function(){
            $("#ad_frm_2").height("200px");
        },1000);    
    });
 
</script>
<style type="text/css">
    .tag_list
    {
        background: none repeat scroll 0 0 #FFFFFF;
        border: 1px solid #D7CBC1;
        color: #000000;
        font-size: 12px;
        line-height: 20px;
        list-style: none outside none;
        margin: 10px 2% 0 1%;
        padding: 1px;
    }
    .tag_list h5
    {
        background: none repeat scroll 0 0 #E0DBD3;
        color: #47381C;
        font-size: 12px;
        height: 24px;
        line-height: 24px;
        padding: 0 5px;
        margin: 0;
    }
    .tag_list h5 a
    {
        color: #47381C;
    }
    .classify
    {
        margin: 10px 0;
        padding: 4px 12px 8px;
    }
    .classify a
    {
        margin-right: 20px;
        white-space: nowrap;
    }
</style>


<div class="tag_list" style="">

    <h5>
        <a href="http://www.csdn.net/tag/" target="_blank">核心技术类目</a></h5>
    <div class="classify">
<a title="全部主题" href="http://www.csdn.net/tag" target="_blank" οnclick="LogClickCount(this,336);">全部主题</a>
<a title="Hadoop" href="http://g.csdn.net/5272865" target="_blank" οnclick="LogClickCount(this,336);">Hadoop</a>
<a title="AWS" href="http://g.csdn.net/5272866" target="_blank" οnclick="LogClickCount(this,336);">AWS</a>
<a title="移动游戏" href="http://g.csdn.net/5272870" target="_blank" οnclick="LogClickCount(this,336);">移动游戏</a>
<a title="Java" href="http://g.csdn.net/5272871" target="_blank" οnclick="LogClickCount(this,336);">Java</a>
<a title="Android" href="http://g.csdn.net/5272872" target="_blank" οnclick="LogClickCount(this,336);">Android</a>
<a title="iOS" href="http://g.csdn.net/5272873" target="_blank" οnclick="LogClickCount(this,336);">iOS</a>
<a title="Swift" href="http://g.csdn.net/5272868" target="_blank" οnclick="LogClickCount(this,336);">Swift</a>
<a title="智能硬件" href="http://g.csdn.net/5272869" target="_blank" οnclick="LogClickCount(this,336);">智能硬件</a>
<a title="Docker" href="http://g.csdn.net/5272867" target="_blank" οnclick="LogClickCount(this,336);">Docker</a>
<a title="OpenStack" href="http://g.csdn.net/5272925" target="_blank" οnclick="LogClickCount(this,336);">OpenStack</a>
<a title="VPN" href="http://www.csdn.net/tag/vpn" target="_blank" οnclick="LogClickCount(this,336);">VPN</a>
<a title="Spark" href="http://g.csdn.net/5272924" target="_blank" οnclick="LogClickCount(this,336);">Spark</a>
<a title="ERP" href="http://www.csdn.net/tag/erp" target="_blank" οnclick="LogClickCount(this,336);">ERP</a>
<a title="IE10" href="http://www.csdn.net/tag/ie10" target="_blank" οnclick="LogClickCount(this,336);">IE10</a>
<a title="Eclipse" href="http://www.csdn.net/tag/eclipse" target="_blank" οnclick="LogClickCount(this,336);">Eclipse</a>
<a title="CRM" href="http://www.csdn.net/tag/crm" target="_blank" οnclick="LogClickCount(this,336);">CRM</a>
<a title="JavaScript" href="http://www.csdn.net/tag/javascript" target="_blank" οnclick="LogClickCount(this,336);">JavaScript</a>
<a title="数据库" href="http://www.csdn.net/tag/数据库" target="_blank" οnclick="LogClickCount(this,336);">数据库</a>
<a title="Ubuntu" href="http://www.csdn.net/tag/ubuntu" target="_blank" οnclick="LogClickCount(this,336);">Ubuntu</a>
<a title="NFC" href="http://www.csdn.net/tag/nfc" target="_blank" οnclick="LogClickCount(this,336);">NFC</a>
<a title="WAP" href="http://www.csdn.net/tag/wap" target="_blank" οnclick="LogClickCount(this,336);">WAP</a>
<a title="jQuery" href="http://www.csdn.net/tag/jquery" target="_blank" οnclick="LogClickCount(this,336);">jQuery</a>
<a title="BI" href="http://www.csdn.net/tag/bi" target="_blank" οnclick="LogClickCount(this,336);">BI</a>
<a title="HTML5" href="http://www.csdn.net/tag/html5" target="_blank" οnclick="LogClickCount(this,336);">HTML5</a>
<a title="Spring" href="http://www.csdn.net/tag/spring" target="_blank" οnclick="LogClickCount(this,336);">Spring</a>
<a title="Apache" href="http://www.csdn.net/tag/apache" target="_blank" οnclick="LogClickCount(this,336);">Apache</a>
<a title=".NET" href="http://www.csdn.net/tag/.net" target="_blank" οnclick="LogClickCount(this,336);">.NET</a>
<a title="API" href="http://www.csdn.net/tag/api" target="_blank" οnclick="LogClickCount(this,336);">API</a>
<a title="HTML" href="http://www.csdn.net/tag/html" target="_blank" οnclick="LogClickCount(this,336);">HTML</a>
<a title="SDK" href="http://www.csdn.net/tag/sdk" target="_blank" οnclick="LogClickCount(this,336);">SDK</a>
<a title="IIS" href="http://www.csdn.net/tag/iis" target="_blank" οnclick="LogClickCount(this,336);">IIS</a>
<a title="Fedora" href="http://www.csdn.net/tag/fedora" target="_blank" οnclick="LogClickCount(this,336);">Fedora</a>
<a title="XML" href="http://www.csdn.net/tag/xml" target="_blank" οnclick="LogClickCount(this,336);">XML</a>
<a title="LBS" href="http://www.csdn.net/tag/lbs" target="_blank" οnclick="LogClickCount(this,336);">LBS</a>
<a title="Unity" href="http://www.csdn.net/tag/unity" target="_blank" οnclick="LogClickCount(this,336);">Unity</a>
<a title="Splashtop" href="http://www.csdn.net/tag/splashtop" target="_blank" οnclick="LogClickCount(this,336);">Splashtop</a>
<a title="UML" href="http://www.csdn.net/tag/uml" target="_blank" οnclick="LogClickCount(this,336);">UML</a>
<a title="components" href="http://www.csdn.net/tag/components" target="_blank" οnclick="LogClickCount(this,336);">components</a>
<a title="Windows Mobile" href="http://www.csdn.net/tag/windowsmobile" target="_blank" οnclick="LogClickCount(this,336);">Windows Mobile</a>
<a title="Rails" href="http://www.csdn.net/tag/rails" target="_blank" οnclick="LogClickCount(this,336);">Rails</a>
<a title="QEMU" href="http://www.csdn.net/tag/qemu" target="_blank" οnclick="LogClickCount(this,336);">QEMU</a>
<a title="KDE" href="http://www.csdn.net/tag/kde" target="_blank" οnclick="LogClickCount(this,336);">KDE</a>
<a title="Cassandra" href="http://www.csdn.net/tag/cassandra" target="_blank" οnclick="LogClickCount(this,336);">Cassandra</a>
<a title="CloudStack" href="http://www.csdn.net/tag/cloudstack" target="_blank" οnclick="LogClickCount(this,336);">CloudStack</a>
<a title="FTC" href="http://www.csdn.net/tag/ftc" target="_blank" οnclick="LogClickCount(this,336);">FTC</a>
<a title="coremail" href="http://www.csdn.net/tag/coremail" target="_blank" οnclick="LogClickCount(this,336);">coremail</a>
<a title="OPhone " href="http://www.csdn.net/tag/ophone " target="_blank" οnclick="LogClickCount(this,336);">OPhone </a>
<a title="CouchBase" href="http://www.csdn.net/tag/couchbase" target="_blank" οnclick="LogClickCount(this,336);">CouchBase</a>
<a title="云计算" href="http://www.csdn.net/tag/云计算" target="_blank" οnclick="LogClickCount(this,336);">云计算</a>
<a title="iOS6" href="http://www.csdn.net/tag/iOS6" target="_blank" οnclick="LogClickCount(this,336);">iOS6</a>
<a title="Rackspace " href="http://www.csdn.net/tag/rackspace " target="_blank" οnclick="LogClickCount(this,336);">Rackspace </a>
<a title="Web App" href="http://www.csdn.net/tag/webapp" target="_blank" οnclick="LogClickCount(this,336);">Web App</a>
<a title="SpringSide" href="http://www.csdn.net/tag/springside" target="_blank" οnclick="LogClickCount(this,336);">SpringSide</a>
<a title="Maemo" href="http://www.csdn.net/tag/maemo" target="_blank" οnclick="LogClickCount(this,336);">Maemo</a>
<a title="Compuware" href="http://www.csdn.net/tag/compuware" target="_blank" οnclick="LogClickCount(this,336);">Compuware</a>
<a title="大数据" href="http://www.csdn.net/tag/大数据" target="_blank" οnclick="LogClickCount(this,336);">大数据</a>
<a title="aptech" href="http://www.csdn.net/tag/aptech" target="_blank" οnclick="LogClickCount(this,336);">aptech</a>
<a title="Perl" href="http://www.csdn.net/tag/perl" target="_blank" οnclick="LogClickCount(this,336);">Perl</a>
<a title="Tornado" href="http://www.csdn.net/tag/tornado" target="_blank" οnclick="LogClickCount(this,336);">Tornado</a>
<a title="Ruby" href="http://www.csdn.net/tag/ruby" target="_blank" οnclick="LogClickCount(this,336);">Ruby</a>
<a title="Hibernate" href="http://www.csdn.net/tag/hibernate" target="_blank" οnclick="LogClickCount(this,336);">Hibernate</a>
<a title="ThinkPHP" href="http://www.csdn.net/tag/thinkphp" target="_blank" οnclick="LogClickCount(this,336);">ThinkPHP</a>
<a title="HBase" href="http://www.csdn.net/tag/hbase" target="_blank" οnclick="LogClickCount(this,336);">HBase</a>
<a title="Pure" href="http://www.csdn.net/tag/pure" target="_blank" οnclick="LogClickCount(this,336);">Pure</a>
<a title="Solr" href="http://www.csdn.net/tag/solr" target="_blank" οnclick="LogClickCount(this,336);">Solr</a>
<a title="Angular" href="http://www.csdn.net/tag/angular" target="_blank" οnclick="LogClickCount(this,336);">Angular</a>
<a title="Cloud Foundry" href="http://www.csdn.net/tag/cloudfoundry" target="_blank" οnclick="LogClickCount(this,336);">Cloud Foundry</a>
<a title="Redis" href="http://www.csdn.net/tag/redis" target="_blank" οnclick="LogClickCount(this,336);">Redis</a>
<a title="Scala" href="http://www.csdn.net/tag/scala" target="_blank" οnclick="LogClickCount(this,336);">Scala</a>
<a title="Django" href="http://www.csdn.net/tag/django" target="_blank" οnclick="LogClickCount(this,336);">Django</a>
<a title="Bootstrap" href="http://www.csdn.net/tag/bootstrap" target="_blank" οnclick="LogClickCount(this,336);">Bootstrap</a>
    </div>

</div>
  <script language="javascript" type="text/javascript">     
      $(function(){
              setTimeout(function(){
                  $.get("/hudashi/svc/GetTagContent",function(data){
                      $(".tag_list").html(data).show();
                  });     
              });
          },500);                       
 </script>


<div id="pop_win" style="display:none ;position: absolute; z-index: 10000; border: 1px solid rgb(220, 220, 220); top: 222.5px; left: 630px; opacity: 1; background: none 0px 0px repeat scroll rgb(255, 255, 255);">
    
</div>
<div id="popup_mask"></div>
<style>
    #popup_mask
    {
        position: absolute;
        width: 100%;
        height: 100%;
        background: #000;
        z-index: 9999;
        left: 0px;
        top: 0px;
        opacity: 0.3;
        filter: alpha(opacity=30);
        display: none;
    }

</style>




<script type="text/javascript">
    $(function(){        
        
        setTimeout(function(){
            $(".comment_body:contains('回复')").each(function(index,item){
                var u=$(this).text().split(':')[0].toString().replace("回复","")
                var thisComment=$(this);
                if(u)
                {
                    $.getJSON("https://passport.csdn.net/get/nick?callback=?", {users: u}, function(a) {
                        if(a!=null&&a.data!=null&&a.data.length>0)
                        {
                            nick=a.data[0].n;
                            if(u!=nick)
                            {
                                thisComment.text(thisComment.text().replace(u,nick));  
                            }
                        }       
                    });  
                }
            });         

        },200);  

        setTimeout(function(){
            $(".math").each(function(index,value){$(this).find("span").last().css("color","#fff"); })
        },5000);

        setTimeout(function(){
            $(".math").each(function(index,value){$(this).find("span").last().css("color","#fff"); })
        },10000);

        setTimeout(function(){
            $(".math").each(function(index,value){$(this).find("span").last().css("color","#fff"); })
        },15000);
        
        setTimeout(function(){
            $("a img[src='http://js.tongji.linezing.com/stats.gif']").parent().css({"position":"absolute","left":"50%"});
        },300);
    });

    function loginbox(){
        var $logpop=$("#pop_win");
        $logpop.html('<iframe src="https://passport.csdn.net/account/loginbox?service=http://static.blog.csdn.net/callback.htm" frameborder="0" height="600" width="400" scrolling="no"></iframe>');

        $('#popup_mask').css({
            opacity: 0.5,
            width: $( document ).width() + 'px',
            height:  $( document ).height() + 'px'
        });
        $('#popup_mask').css("display","block");
 
        $logpop.css( {
            top: ($( window ).height() - $logpop.height())/ 2  + $( window
       ).scrollTop() + 'px',
            left:($( window ).width() - $logpop.width())/ 2
        } );
 
        setTimeout( function () {
            $logpop.show();
            $logpop.css( {
                opacity: 1
            } );
        }, 200 );
 
        $('#popup_mask').unbind("click");
        $('#popup_mask').bind("click", function(){
            $('#popup_mask').hide();
            var $clopop = $("#pop_win");
            $("#common_ask_div_sc").css("display","none");
            $clopop.css( {
                opacity: 0
            } );
            setTimeout( function () {
                $clopop.hide();
            }, 350 );
            return false;
        });
    }   

</script>
 <script language="javascript" type="text/javascript" src="http://ads.csdn.net/js/async_new.js"></script>      




                        <div class="clear">
                        </div>
                    </div>                   
                
            </div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值