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

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## 替換 Git 對象是不可改變的,但它提供一種有趣的方式來用其他對象假裝替換數據庫中的 Git 對象。 `replace`?命令可以讓你在 Git 中指定一個對象并可以聲稱“每次你遇到這個 Git 對象時,假裝它是其他的東西”。 在你用一個不同的提交替換歷史中的一個提交時,這會非常有用。 例如,你有一個大型的代碼歷史并想把自己的倉庫分成一個短的歷史和一個更大更長久的歷史,短歷史供新的開發者使用,后者給喜歡數據挖掘的人使用。 你可以通過用新倉庫中最早的提交?`replace`老倉庫中最新的提交來連接歷史,這種方式可以把一條歷史移植到其他歷史上。 這意味著你不用在新歷史中真正替換每一個提交(因為歷史來源會影響 SHA 的值),你可以加入他們。 讓我們來試試吧。 首先獲取一個已經存在的倉庫,并將其分成兩個倉庫,一個是最近的倉庫,一個是歷史版本的倉庫,然后我們將看到如何在不更改倉庫 SHA 值的情況下通過?`replace`?命令來合并他們。 我們將使用一個擁有 5 個提交的簡單倉庫: ~~~ $ git log --oneline ef989d8 fifth commit c6e1e95 fourth commit 9c68fdc third commit 945704c second commit c1822cf first commit ~~~ 我們想將其分成拆分成兩條歷史。 第一個到第四個提交的作為第一個歷史版本。 第四、第五個提交的作為最近的第二個歷史版本。 ![](https://box.kancloud.cn/2015-10-12_561bcb96c8943.png) Figure 7-28. 創建歷史版本的歷史很容易,我們可以只將一個歷史中的分支推送到一個新的遠程倉庫的 master 分支。 ~~~ $ git branch history c6e1e95 $ git log --oneline --decorate ef989d8 (HEAD, master) fifth commit c6e1e95 (history) fourth commit 9c68fdc third commit 945704c second commit c1822cf first commit ~~~ ![](https://box.kancloud.cn/2015-10-12_561bcb96e2bfb.png) Figure 7-29. 現在我們可以把這個新的?`history`?分支推送到我們新倉庫的?`master`?分支: ~~~ $ git remote add project-history https://github.com/schacon/project-history $ git push project-history history:master Counting objects: 12, done. Delta compression using up to 2 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (12/12), 907 bytes, done. Total 12 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (12/12), done. To git@github.com:schacon/project-history.git * [new branch] history -> master ~~~ 這樣一來,我們的歷史版本就發布了。 稍難的部分則是刪減我們最近的歷史來讓它變得更小。 我們需要一個重疊以便于用一個相等的提交來替換另一個提交,這樣一來,我們將截斷到第四、五個提交。 ~~~ $ git log --oneline --decorate ef989d8 (HEAD, master) fifth commit c6e1e95 (history) fourth commit 9c68fdc third commit 945704c second commit c1822cf first commit ~~~ 在這種情況下,創建一個能夠指導擴展歷史的基礎提交是很有用的。 這樣一來,如果其他的開發者想要修改第一次提交或者其他操作時就知道要做些什么,因此,接下來我們要做的是用命令創建一個最初的提交對象,然后將剩下的提交(第四、第五個提交)變基到它的上面。 為了這么做,我們需要選擇一個點去拆分,對于我們而言是第三個提交(SHA 是?`9c68fdc`)。因此我們的提交將基于此提交樹。我們可以使用?`commit-tree`?命令來創建基礎提交,這樣我們就有了一個樹,并返回一個全新的、無父節點的 SHA 提交對象。 ~~~ $ echo 'get history from blah blah blah' | git commit-tree 9c68fdc^{tree} 622e88e9cbfbacfb75b5279245b9fb38dfea10cf ~~~ > ###### NOTE > `commit-tree`?命令屬于底層指令。有許多指令并非直接使用,而是被?**其他的**?Git 命令用來做更小一些的工作。有時當我們做一些像這樣的奇怪事情時,它們允許我們做一些不適用于日常使用但真正底層的東西。更多關于底層命令的內容請參見?[底層命令和高層命令](http://git-scm.com/book/zh/v2/1-git-internals/_plumbing_porcelain) ![](https://box.kancloud.cn/2015-10-12_561bcb9706d04.png) Figure 7-30. 現在我們已經有一個基礎提交了,我們可以通過?`git rebase --onto`?命令來將剩余的歷史變基到基礎提交之上。`--onto`?參數是剛才?`commit-tree`?命令返回的 SHA 值,變基點會成為第三個提交(我們想留下的第一個提交的父提交,`9c68fdc`): ~~~ $ git rebase --onto 622e88 9c68fdc First, rewinding head to replay your work on top of it... Applying: fourth commit Applying: fifth commit ~~~ ![](https://box.kancloud.cn/2015-10-12_561bcb9724c0f.png) Figure 7-31. 我們已經用基礎提交重寫了最近的歷史,基礎提交包括如何重新組成整個歷史的說明。 我們可以將新歷史推送到新項目中,當其他人克隆這個倉庫時,他們僅能看到最近兩次提交以及一個包含上述說明的基礎提交。 現在我們將以想獲得整個歷史的人的身份來初次克隆這個項目。 在克隆這個截斷后的倉庫后為了得到歷史數據,需要添加第二個遠程的歷史版本庫并對其做獲取操作: ~~~ $ git clone https://github.com/schacon/project $ cd project $ git log --oneline master e146b5f fifth commit 81a708d fourth commit 622e88e get history from blah blah blah $ git remote add project-history https://github.com/schacon/project-history $ git fetch project-history From https://github.com/schacon/project-history * [new branch] master -> project-history/master ~~~ 現在,協作者在?`master`?分支中擁有他們最近的提交并且在?`project-history/master`?分支中擁有過去的提交。 ~~~ $ git log --oneline master e146b5f fifth commit 81a708d fourth commit 622e88e get history from blah blah blah $ git log --oneline project-history/master c6e1e95 fourth commit 9c68fdc third commit 945704c second commit c1822cf first commit ~~~ 為了合并它們,你可以使用?`git replace`?命令加上你想替換的提交信息來進行替換。 這樣一來,我們就可以將 master 分支中的第四個提交替換為?`project-history/master`?分支中的“第四個”提交。 ~~~ $ git replace 81a708d c6e1e95 ~~~ 現在,查看?`master`?分支中的歷史信息,顯示如下: ~~~ $ git log --oneline master e146b5f fifth commit 81a708d fourth commit 9c68fdc third commit 945704c second commit c1822cf first commit ~~~ 很酷,是不是?不用改變上游的 SHA-1 我們就能用一個提交來替換歷史中的所有不同的提交,并且所有的工具(`bisect`,`blame`?等)也都奏效。 ![](https://box.kancloud.cn/2015-10-12_561bcb973de7f.png) Figure 7-32. 有趣的是,即使是使用了?`c6e1e95`?提交數據來進行替換,它的 SHA-1 仍顯示為?`81a708d`。 即使你運行了?`cat-file`?命令,它仍會顯示你替換的數據: ~~~ $ git cat-file -p 81a708d tree 7bc544cf438903b65ca9104a1e30345eee6c083d parent 9c68fdceee073230f19ebb8b5e7fc71b479c0252 author Scott Chacon <schacon@gmail.com> 1268712581 -0700 committer Scott Chacon <schacon@gmail.com> 1268712581 -0700 fourth commit ~~~ 請記住,`81a708d`?真正的父提交是?`622e882`?占位提交,而非呈現的?`9c68fdce`?提交。 另一個有趣的事情是數據將會以以下引用顯示: ~~~ $ git for-each-ref e146b5f14e79d4935160c0e83fb9ebe526b8da0d commit refs/heads/master c6e1e95051d41771a649f3145423f8809d1a74d4 commit refs/remotes/history/master e146b5f14e79d4935160c0e83fb9ebe526b8da0d commit refs/remotes/origin/HEAD e146b5f14e79d4935160c0e83fb9ebe526b8da0d commit refs/remotes/origin/master c6e1e95051d41771a649f3145423f8809d1a74d4 commit refs/replace/81a708dd0e167a3f691541c7a6463343bc457040 ~~~ 這意味著我們可以輕而易舉的和其他人分享替換,因為我們可以將替換推送到服務器中并且其他人可以輕松地下載。 也許在歷史移植情況下不是很有用(既然每個人都樂意下載最新版本和歷史版本,為何還要拆分他們呢?),但在其他情況下仍然很有用。
                  <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>

                              哎呀哎呀视频在线观看