<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 搜索 無論倉庫里的代碼量有多少,你經常需要查找一個函數是在哪里調用或者定義的,或者一個方法的變更歷史。 Git 提供了兩個有用的工具來快速地從它的數據庫中瀏覽代碼和提交。 我們來簡單的看一下。 ### [Git Grep](http://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E6%90%9C%E7%B4%A2#Git-Grep) Git 提供了一個?`grep`?命令,你可以很方便地從提交歷史或者工作目錄中查找一個字符串或者正則表達式。 我們用 Git 本身源代碼的查找作為例子。 默認情況下 Git 會查找你工作目錄的文件。 你可以傳入?`-n`?參數來輸出 Git 所找到的匹配行行號。 ~~~ $ git grep -n gmtime_r compat/gmtime.c:3:#undef gmtime_r compat/gmtime.c:8: return git_gmtime_r(timep, &result); compat/gmtime.c:11:struct tm *git_gmtime_r(const time_t *timep, struct tm *result) compat/gmtime.c:16: ret = gmtime_r(timep, result); compat/mingw.c:606:struct tm *gmtime_r(const time_t *timep, struct tm *result) compat/mingw.h:162:struct tm *gmtime_r(const time_t *timep, struct tm *result); date.c:429: if (gmtime_r(&now, &now_tm)) date.c:492: if (gmtime_r(&time, tm)) { git-compat-util.h:721:struct tm *git_gmtime_r(const time_t *, struct tm *); git-compat-util.h:723:#define gmtime_r git_gmtime_r ~~~ `grep`?命令有一些有趣的選項。 例如,你可以使用?`--count`?選項來使 Git 輸出概述的信息,僅僅包括哪些文件包含匹配以及每個文件包含了多少個匹配。 ~~~ $ git grep --count gmtime_r compat/gmtime.c:4 compat/mingw.c:1 compat/mingw.h:1 date.c:2 git-compat-util.h:2 ~~~ 如果你想看匹配的行是屬于哪一個方法或者函數,你可以傳入?`-p`?選項: ~~~ $ git grep -p gmtime_r *.c date.c=static int match_multi_number(unsigned long num, char c, const char *date, char *end, struct tm *tm) date.c: if (gmtime_r(&now, &now_tm)) date.c=static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt) date.c: if (gmtime_r(&time, tm)) { ~~~ 在這里我們可以看到在 date.c 文件中有?`match_multi_number`?和?`match_digit`?兩個函數調用了?`gmtime_r`。 你還可以使用?`--and`?標志來查看復雜的字符串組合,也就是在同一行同時包含多個匹配。 比如,我們要查看在舊版本 1.8.0 的 Git 代碼庫中定義了常量名包含 “LINK” 或者 “BUF_MAX” 這兩個字符串所在的行。 這里我們也用到了?`--break`?和?`--heading`?選項來使輸出更加容易閱讀。 ~~~ $ git grep --break --heading \ -n -e '#define' --and \( -e LINK -e BUF_MAX \) v1.8.0 v1.8.0:builtin/index-pack.c 62:#define FLAG_LINK (1u<<20) v1.8.0:cache.h 73:#define S_IFGITLINK 0160000 74:#define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK) v1.8.0:environment.c 54:#define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS v1.8.0:strbuf.c 326:#define STRBUF_MAXLINK (2*PATH_MAX) v1.8.0:symlinks.c 53:#define FL_SYMLINK (1 << 2) v1.8.0:zlib.c 30:/* #define ZLIB_BUF_MAX ((uInt)-1) */ 31:#define ZLIB_BUF_MAX ((uInt) 1024 * 1024 * 1024) /* 1GB */ ~~~ 相比于一些常用的搜索命令比如?`grep`?和?`ack`,`git grep`?命令有一些的優點。 第一就是速度非常快,第二是你不僅僅可以可以搜索工作目錄,還可以搜索任意的 Git 樹。 在上一個例子中,我們在一個舊版本的 Git 源代碼中查找,而不是當前檢出的版本。 ### [Git 日志搜索](http://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E6%90%9C%E7%B4%A2#Git-日志搜索) 或許你不想知道某一項在?**哪里**?,而是想知道是什么?**時候**?存在或者引入的。?`git log`?命令有許多強大的工具可以通過提交信息甚至是 diff 的內容來找到某個特定的提交。 例如,如果我們想找到?`ZLIB_BUF_MAX`?常量是什么時候引入的,我們可以使用?`-S`?選項來顯示新增和刪除該字符串的提交。 ~~~ $ git log -SZLIB_BUF_MAX --oneline e01503b zlib: allow feeding more than 4GB in one go ef49a7a zlib: zlib can only process 4GB at a time ~~~ 如果我們查看這些提交的 diff,我們可以看到在?`ef49a7a`?這個提交引入了常量,并且在`e01503b`?這個提交中被修改了。 如果你希望得到更精確的結果,你可以使用?`-G`?選項來使用正則表達式搜索。 #### 行日志搜索 行日志搜索是另一個相當高級并且有用的日志搜索功能。 這是一個最近新增的不太知名的功能,但卻是十分有用。 在?`git log`?后加上?`-L`?選項即可調用,它可以展示代碼中一行或者一個函數的歷史。 例如,假設我們想查看?`zlib.c`?文件中`git_deflate_bound`?函數的每一次變更,我們可以執行`git log -L :git_deflate_bound:zlib.c`。 Git 會嘗試找出這個函數的范圍,然后查找歷史記錄,并且顯示從函數創建之后一系列變更對應的補丁。 ~~~ $ git log -L :git_deflate_bound:zlib.c commit ef49a7a0126d64359c974b4b3b71d7ad42ee3bca Author: Junio C Hamano <gitster@pobox.com> Date: Fri Jun 10 11:52:15 2011 -0700 zlib: zlib can only process 4GB at a time diff --git a/zlib.c b/zlib.c --- a/zlib.c +++ b/zlib.c @@ -85,5 +130,5 @@ -unsigned long git_deflate_bound(z_streamp strm, unsigned long size) +unsigned long git_deflate_bound(git_zstream *strm, unsigned long size) { - return deflateBound(strm, size); + return deflateBound(&strm->z, size); } commit 225a6f1068f71723a910e8565db4e252b3ca21fa Author: Junio C Hamano <gitster@pobox.com> Date: Fri Jun 10 11:18:17 2011 -0700 zlib: wrap deflateBound() too diff --git a/zlib.c b/zlib.c --- a/zlib.c +++ b/zlib.c @@ -81,0 +85,5 @@ +unsigned long git_deflate_bound(z_streamp strm, unsigned long size) +{ + return deflateBound(strm, size); +} + ~~~ 如果 Git 無法計算出如何匹配你代碼中的函數或者方法,你可以提供一個正則表達式。 例如,這個命令和上面的是等同的:`git log -L '/unsigned long git_deflate_bound/',/^}/:zlib.c`。 你也可以提供單行或者一個范圍的行號來獲得相同的輸出。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看