<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                這一章我們會學習如何在更低的層次操作Git, 以防你需要自己寫一個新工具去人工生成blob(塊), tree(樹)或者commit(提交)對象. 如果你想使用更加底層的Git命令去寫腳本, 你會需要用到以下的命令. ## 創建blob對象 在你的Git倉庫中創建一個blob對象并且得到它的SHA值是很容易的, 使用[git hash-object](http://www.kernel.org/pub/software/scm/git/docs/git-hash-object.html)就足夠了. 要使用一個現有的文件去創建新blob, 使用'-w'選項去運行前面提到的命令('-w'選項告訴Git要生成blob, 而不是僅僅計算SHA值). ~~~ $ git hash-object -w myfile.txt 6ff87c4664981e4397625791c8ea3bbb5f2279a3 $ git hash-object -w myfile2.txt 3bb0e8592a41ae3185ee32266c860714980dbed7 ~~~ 標準輸出中顯示的值就是創建的blob的SHA值. ## 創建tree對象 假設你要使用你創建的一些對象去組建一棵樹, 按照[git ls-tree](http://www.kernel.org/pub/software/scm/git/docs/git-ls-tree.html)的格式組織好輸入,?[git mktree](http://www.kernel.org/pub/software/scm/git/docs/git-mktree.html)就可以為你生成需要的tree對象. 例如, 如果你把下面的信息寫入到'/tmp/tree.txt'中: ~~~ 100644 blob 6ff87c4664981e4397625791c8ea3bbb5f2279a3 file1 100644 blob 3bb0e8592a41ae3185ee32266c860714980dbed7 file2 ~~~ 然后通過管道把這些信息輸入到[git mktree](http://www.kernel.org/pub/software/scm/git/docs/git-mktree.html)中, Git會生成一個新的tree對象, 把它寫入到對象數據庫(object database)中, 然后返回tree對象的SHA值. ~~~ $ cat /tmp/tree.txt | git mk-tree f66a66ab6a7bfe86d52a66516ace212efa00fe1f ~~~ 然后, 我們可以把剛才生成的tree作為另外一個tree的子目錄, 等等等等. 如果我們需要創建一個帶子樹的樹對象(這個子樹就是前面生成的tree對象), 只需創建一個新文件(/tmp/newtree.txt), 把前面的tree對象的SHA值寫入: ~~~ 100644 blob 6ff87c4664981e4397625791c8ea3bbb5f2279a3 file1-copy 040000 tree f66a66ab6a7bfe86d52a66516ace212efa00fe1f our_files ~~~ 然后再次調用[git mk-tree](http://www.kernel.org/pub/software/scm/git/docs/git-mk-tree.html): ~~~ $ cat /tmp/newtree.txt | git mk-tree 5bac6559179bd543a024d6d187692343e2d8ae83 ~~~ 現在我們有了一個人工創建的目錄結構: ~~~ . |-- file1-copy `-- our_files |-- file1 `-- file2 1 directory, 3 files ~~~ 但是上面的結構并不在磁盤上存在. 另外, 我們使用SHA值去指向它(`5bac6559`). ## 重新組織樹 我們也可以使用索引文件把樹嵌入到新的結構中. 舉個簡單的例子, 我們使用一個臨時索引文件創建一棵新的樹, 其中包含了`5bac6559`這棵樹的兩個副本. (設置GIT_INDEX_FILE環境變量使之指向臨時索引文件) 首先, 用[git read-tree](http://www.kernel.org/pub/software/scm/git/docs/git-read-tree.html)把樹對象讀入到臨時索引文件中, 并給每個副本一個新的前綴; 然后再用[git write-tree](http://www.kernel.org/pub/software/scm/git/docs/git-write-tree.html)把索引中的內容生成一棵新的樹: ~~~ $ export GIT_INDEX_FILE=/tmp/index $ git read-tree --prefix=copy1/ 5bac6559 $ git read-tree --prefix=copy2/ 5bac6559 $ git write-tree bb2fa6de7625322322382215d9ea78cfe76508c1 $>git ls-tree bb2fa 040000 tree 5bac6559179bd543a024d6d187692343e2d8ae83 copy1 040000 tree 5bac6559179bd543a024d6d187692343e2d8ae83 copy2 ~~~ 現在我們可以看到, 通過操縱索引文件可以得到一棵新的樹. 你也可以在臨時索引文件中做合并等操作 - 請參見[git read-tree](http://www.kernel.org/pub/software/scm/git/docs/git-read-tree.html)取得更多信息. ## 創建commit對象 現在我們有了一棵樹的SHA值, 我們可以使用[git commit-tree](http://www.kernel.org/pub/software/scm/git/docs/git-commit-tree.html)命令創建一個指向它的commit對象. 大部分commit對象的數據都是通過環境變量來設定的, 你需要設置下面的環境變量: ~~~ GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE ~~~ 然后你把你的提交信息寫入到一個文件中并且通過管道傳送給[git commit-tree](http://www.kernel.org/pub/software/scm/git/docs/git-commit-tree.html), 即可得到一個commit對象. ~~~ $ git commit-tree bb2fa < /tmp/message a5f85ba5875917319471dfd98dfc636c1dc65650 ~~~ 如果你需要指定一個或多個父commit對象, 只需要使用'-p'參數一個一個指定父commit對象. 同樣的, 新對象的SHA值通過STDOUT返回. ## 更新分支的引用 現在我得拿到了新的commit對象的SHA值, 如有需要, 我們可以使用一個分支指向它. 比如說我們需要更新'master'分支的引用, 使其指向剛剛創建的新對象, 我們可以使用[git update-ref](http://www.kernel.org/pub/software/scm/git/docs/git-update-ref.html)去完成這個工作: ~~~ $ git update-ref refs/heads/master a5f85ba5875917319471dfd98dfc636c1dc65650 ~~~
                  <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>

                              哎呀哎呀视频在线观看