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