Git 是一款开源优秀的版本管理工具,它最初由 Linus Torvalds 等人开发,用于管理 Linux Kernel 的版本研发。相关的书籍和教程网上琳琅满目,它们多数都详细的介绍其基本的使用和命令。本人根据本身的经验,整理出几个较为高级而经常使用的命令。html
推荐资料 Git Book。node
Git blame 能够查询每一行代码的 commit ID、提交者和提交日期。git
$ 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 blame,从而查询整个 patch。api
$ 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 某个分支的每次操做,一般用来恢复误操做影响的数据。dom
$ 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 可从其它分支抓取 commit 合入当前分支中,经常使用于从 upstream 合入 patch。koa
$ git cherry-pick -x commit_id
Git rebase 无疑是最为复杂、最难以理解,固然也是很是强大的命令,经常使用于合并分支,能够简单的理解为一系列的 git cherry-pick,它具备如下功能。ide
合并分支
从新修改 Commit,如合并 commit,调整 commit 的顺序。
Git rebase 用法请见 Git Book,可是使用时,请注意如下准则:工具
The golden rule of git rebase is to never use it on public branches.code
来源: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.htmlserver