乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      [Git] Git整理(五) git cherry

       bylele 2019-10-08

      概述

      git cherry-pick可以理解為”挑揀”提交,它會獲取某一個分支的單筆提交,并作為一個新的提交引入到你當前分支上。 當我們需要在本地合入其他分支的提交時,如果我們不想對整個分支進行合并,而是只想將某一次提交合入到本地當前分支上,那么就要使用git cherry-pick了。

      用法

      git cherry-pick [<options>] <commit-ish>...
      
      常用options:
          --quit                退出當前的chery-pick序列
          --continue            繼續(xù)當前的chery-pick序列
          --abort               取消當前的chery-pick序列,恢復當前分支
          -n, --no-commit       不自動提交
          -e, --edit            編輯提交信息
      git cherry-pick commitid

      在本地倉庫中,有兩個分支:branch1和branch2,我們先來查看各個分支的提交:

      # 切換到branch2分支
      $ git checkout branch2
      Switched to branch 'branch2'
      $ 
      $ 
      # 查看最近三次提交
      $ git log --oneline -3
      23d9422 [Description]:branch2 commit 3
      2555c6e [Description]:branch2 commit 2
      b82ba0f [Description]:branch2 commit 1
      # 切換到branch1分支
      $ git checkout branch1
      Switched to branch 'branch1'
      # 查看最近三次提交
      $ git log --oneline -3
      20fe2f9 commit second
      c51adbe commit first
      ae2bd14 commit 3th
      

      現(xiàn)在,我想要將branch2分支上的第一次提交內容合入到branch1分支上,則可以使用git cherry-pick命令:

      $ git cherry-pick 2555c6e
      error: could not apply 2555c6e... [Description]:branch2 commit 2
      hint: after resolving the conflicts, mark the corrected paths
      hint: with 'git add <paths>' or 'git rm <paths>'
      hint: and commit the result with 'git commit'
      

      cherry-pick時,沒有成功自動提交,這說明存在沖突,因此首先需要解決沖突,解決沖突后需要git commit手動進行提交:

      $ git commit 
      [branch1 790f431] [Description]:branch2 commit 2
       Date: Fri Jul 13 18:36:44 2018 +0800
       1 file changed, 1 insertion(+)
       create mode 100644 only-for-branch2.txt
      

      或者git add .后直接使用git cherry-pick --continue繼續(xù)。
      現(xiàn)在查看提交信息:

      $ git log --oneline -3
      790f431 [Description]:branch2 commit 2
      20fe2f9 commit second
      c51adbe commit first
      

      branch2分支上的第二次提交成功合入到了branch1分支上。

      以上就是git cherry-pick的基本用法,如果沒有出現(xiàn)沖突,該命令將自動提交。

      git cherry-pick -n

      如果不想git cherry-pick自動進行提交,則加參數(shù)-n即可。比如將branch2分支上的第三次提交內容合入到branch1分支上:

      $ git cherry-pick 23d9422
      [branch1 2c67715] [Description]:branch2 commit 3
       Date: Fri Jul 13 18:37:05 2018 +0800
       1 file changed, 1 insertion(+)
      $ 
      

      查看提交log,它自動合入了branch1分支:

      $ git log --oneline -3
      2c67715 [Description]:branch2 commit 3
      f8bc5db [Description]:branch2 commit 2
      20fe2f9 commit second
      

      如果不想進行自動合入,則使用git cherry-pick -n

      # 回退上次提交,再此進行cherry-pick
      $ git reset --hard HEAD~
      HEAD is now at f8bc5db [Description]:branch2 commit 2
      $ git cherry-pick -n 23d9422
      $ git status
      On branch branch1
      Changes to be committed:
        (use "git reset HEAD <file>..." to unstage)
      
          modified:   only-for-branch2.txt
      
      $ 

      這時通過git status查看,發(fā)現(xiàn)已將branch2的提交獲取但是沒有合入。

      git cherry-pick -e

      如果想要在cherr-pick后重新編輯提交信息,則使用git cherry-pick -e命令,比如我們還是要將branch2分支上的第三次提交內容合入到branch1分支上,但是需要修改提交信息:

      $ git cherry-pick -e 23d9422
      
        1 [Description]:branch2 commit 3
        2 #
        3 # It looks like you may be committing a cherry-pick.
        4 # If this is not correct, please remove the file
        5 #       .git/CHERRY_PICK_HEAD
        6 # and try again.
      

      git cherry-pick –continue, –abort,–quit

      當使用git cherry-pick發(fā)生沖突后,將會出現(xiàn)如下信息:

      $ git cherry-pick 23d9422
      error: could not apply 23d9422... [Description]:branch2 commit 3
      hint: after resolving the conflicts, mark the corrected paths
      hint: with 'git add <paths>' or 'git rm <paths>'
      hint: and commit the result with 'git commit'

      這時如果要繼續(xù)cherry-pick,則首先需要解決沖突,通過git add .將文件標記為已解決,然后可以使用git cherry-pick --continue命令,繼續(xù)進行cherry-pick操作。

      如果要中斷這次cherry-pick,則使用git cherry-pick --quit,這種情況下當前分支中未沖突的內容狀態(tài)將為modified,

      如果要取消這次cherry-pick,則使用git cherry-pick --abort,這種情況下當前分支恢復到cherry-pick前的狀態(tài),沒有改變。

      git cherry-pick < branchname >

      如果在git cherry-pick后加一個分支名,則表示將該分支頂端提交進cherry-pick,如:

      $ git cherry-pick master

      git cherry-pick ..< branchname >

      git cherry-pick ^HEAD < branchname >

      以上兩個命令作用相同,表示應用所有提交引入的更改,這些提交是branchname的祖先但不是HEAD的祖先,比如,現(xiàn)在我的倉庫中有三個分支,其提交歷史如下圖:

                     C<---D<---E  branch2
                    /
      master   A<---B  
                                   F<---G<---H  branch3
                               |
                               HEAD

      如果我使用git cherry-pick ..branch2或者git cherry-pick ^HEAD branch2,那么會將屬于branch2的祖先但不屬于branch3的祖先的所有提交引入到當前分支branch3上,并生成新的提交,執(zhí)行命令如下:

      $ git cherry-pick ..branch2
      [branch3 c95d8b0] [Description]:branch2  add only-for-branch2
       Date: Fri Jul 13 20:34:40 2018 +0800
       1 file changed, 0 insertions(+), 0 deletions(-)
       create mode 100644 only-for-branch2
      [branch3 7199a67] [Description]:branch2 modify for only-for-branch2--1
       Date: Fri Jul 13 20:38:35 2018 +0800
       1 file changed, 1 insertion(+)
      [branch3 eb8ab62] [Description]:branch2 modify for only-for-branch2--2
       Date: Fri Jul 13 20:39:09 2018 +0800
       1 file changed, 1 insertion(+)

      執(zhí)行后的提交歷史如下:

      
                     C<---D<---E  branch2
                    /
      master   A<---B  
                                   F<---G<---H<---C'<---D'<---E'  branch3
                                                |
                                               HEAD
      

      常見問題

      1.The previous cherry-pick is now empty, possibly due to conflict resolution.
      原因:

      cherry-pick時出現(xiàn)沖突,解決沖突后本地分支中內容和cherry-pick之前相比沒有改變,因此當在以后的步驟中繼續(xù)git cherry-pick或執(zhí)行其他命令時,由于此時還處于上次cherry-pick,都會提示該信息,表示可能是由于解決沖突造成上一次cherry-pick內容是空的。

      解決方案:
      • 1.執(zhí)行git cherry-pick --abort取消上次操作。

      • 2.執(zhí)行git commit --allow-empty,表示允許空提交。

      2.fatal: You are in the middle of a cherry-pick – cannot amend.
      原因:

      cherry-pick時出現(xiàn)沖突,沒有解決沖突就執(zhí)行git commit --amend命令,從而會提示該信息。

      解決方案:

      首先在git commit --amend之前解決沖突,并完成這次cherry-pick:

      $ git add .
      $ git cherry-pick --continue

        本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
        轉藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多