• 几个常用的 Git 高级命令


    Git 是一款开源优秀的版本管理工具,它最初由 Linus Torvalds 等人开发,用于管理 Linux Kernel 的版本研发。相关的书籍和教程网上琳琅满目,它们多数都详细的介绍其基本的使用和命令。本人根据自己的经验,整理出几个较为高级而常用的命令。

    推荐资料 Git Book。

    Git blame

    Git blame 可以查询每一行代码的 commit ID、提交者和提交日期。

    $ git blame nova/api/openstack/compute/servers.py
    
    5b866f3a nova/api/openstack/v2/servers.py               (Kevin L. Mitchell        2012-01-09 13:13:08 -0600  776)     @wsgi.response(202)
    5b866f3a nova/api/openstack/v2/servers.py               (Kevin L. Mitchell        2012-01-09 13:13:08 -0600  777)     @wsgi.serializers(xml=FullServerTemplate)
    5b866f3a nova/api/openstack/v2/servers.py               (Kevin L. Mitchell        2012-01-09 13:13:08 -0600  778)     @wsgi.deserializers(xml=CreateDeserializer)
    5b866f3a nova/api/openstack/v2/servers.py               (Kevin L. Mitchell        2012-01-09 13:13:08 -0600  779)     def create(self, req, body):
    cc642ff1 nova/api/openstack/compute/servers.py          (Alex Meade               2012-04-15 21:44:15 -0400  780)         """Creates a new server for a given user."""
    d1ad73ee nova/api/openstack/compute/servers.py          (Mark McLoughlin          2012-09-12 12:50:53 +0100  781)         if not self.is_valid_body(body, 'server'):
    5b866f3a nova/api/openstack/v2/servers.py               (Kevin L. Mitchell        2012-01-09 13:13:08 -0600  782)             raise exc.HTTPUnprocessableEntity()
    

      

     

    Git show

    确切的说,Git show 并非是一个高级命令,只是它经常配合 git blame,从而查询整个 patch。

    $ git show 5b866f3a
    
    ...
    
    diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py
    index 5def03f..e96c42a 100644
    --- a/nova/api/openstack/common.py
    +++ b/nova/api/openstack/common.py
    @@ -334,6 +334,21 @@ def get_networks_for_instance(context, instance):
         return networks
    
    +class MetadataDeserializer(wsgi.MetadataXMLDeserializer):
    +    def deserialize(self, text):
    +        dom = minidom.parseString(text)
    +        metadata_node = self.find_first_child_named(dom, "metadata")
    +        metadata = self.extract_metadata(metadata_node)
    
    ...
    

      

    Git reflog

    Git reflog 记录了 git 某个分支的每次操作,通常用来恢复误操作影响的数据。

    $ git reflog
    
    1dcfb0f HEAD@{0}: reset: moving to 1dcfb0f
    d5640a9 HEAD@{1}: checkout: moving from test to master
    1dcfb0f HEAD@{2}: checkout: moving from icehouse to test
    
    $ git reset d5640a9
    

      

    Git cherry-pick

    Git cherry-pick 可从其它分支抓取 commit 合入当前分支中,常用于从 upstream 合入 patch。

    $ git cherry-pick -x commit_id
    

      

    Git rebase

    Git rebase 无疑是最为复杂、最难以理解,当然也是非常强大的命令,常用于合并分支,可以简单的理解为一系列的 git cherry-pick,它具有以下功能。

    合并分支
    重新修改 Commit,如合并 commit,调整 commit 的顺序。
    Git rebase 用法请见 Git Book,但是使用时,请注意以下准则:

    The golden rule of git rebase is to never use it on public branches.

    来源:koala bear
    链接:http://wsfdl.com/devops/2014/11/20/%E5%87%A0%E4%B8%AA%E5%B8%B8%E7%94%A8%E7%9A%84git%E9%AB%98%E7%BA%A7%E5%91%BD%E4%BB%A4.html

    更多干货领取可关注公众号后回复“干货”即可免费领取海量干货

  • 相关阅读:
    JSONArray数据转换成java List
    js格式化格林威治时间
    JS实现等比例缩放图片
    oracle显示一个月的所有天数
    Oracle行转列、列转行的Sql语句总结
    当echarts的legend字数过多的时候变成省略号
    oracle获取今年在内的前几年、后几年
    JAVA方法调用中的解析与分派
    static 和 final 关键字 对实例变量赋初始值的影响
    从虚拟机指令执行的角度分析JAVA中多态的实现原理
  • 原文地址:https://www.cnblogs.com/xdclass/p/9854923.html
Copyright © 2020-2023  润新知