日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

git中cherry-pick命令的使用教程_其它綜合

作者:小旭2021 ? 更新時間: 2022-08-16 編程語言

git cherry-pick可以選擇某一個分支中的一個或幾個commit(s)來進行操作。例如,假設我們有個穩定版本的分支,叫v2.0,另外還有個開發版本的分支v3.0,我們不能直接把兩個分支合并,這樣會導致穩定版本混亂,但是又想增加一個v3.0中的功能到v2.0中,這里就可以使用cherry-pick了,其實也就是對已經存在的commit 進行再次提交。

簡單用法:

git cherry-pick <commit id>

例如:

$ git checkout v2.0分支
$ git cherry-pick 38361a55 # 這個 38361a55 號碼,位于v3.0分支中:

$ git log
commit 38361a55138140827b31b72f8bbfd88b3705d77a
Author: Justin Justin@xxx.com
Date: Sat Dec 10 00:11:44 2016 +0800

1. 如果順利,就會正常提交。結果:

Finished one cherry-pick.
On branch v2.0分支
Your branch is ahead of 'origin/old_cc' by 3 commits.

2. 如果在cherry-pick 的過程中出現了沖突

Automatic cherry-pick failed.
After resolving the conflicts,mark the corrected paths with 'git add <paths>' or 'git rm <paths>'and commit the result with:
git commit -c 15a2b6c61927e5aed6111de89ad9dafba939a90b

或者:

error: could not apply 0549563... dev
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'

就跟普通的沖突一樣,手工解決:

2.1 $ git status # 看哪些文件出現沖突

both modified: app/models/MainActivity.java

2.2 $ vim app/models/MainActivity.java # 手動解決它。

2.3 $ git add app/models/MainActivity.java

2.4 git commit -c <新的commit號碼>

2.5 再次cherry-pick剩余commit

若提示:

error: a cherry-pick or revert is already in progress
hint: try "git cherry-pick (--continue | --quit | --abort)"
fatal: cherry-pick failed

則執行對應操作:

git cherry-pick --continue
git cherry-pick --quit
git cherry-pick --abort

命令集合:

git cherry-pick <commit id>:單獨合并一個提交
git cherry-pick -x <commit id>:同上,不同點:保留原提交者信息。
Git從1.7.2版本開始支持批量cherry-pick,就是一次可以cherry-pick一個區間的commit。
git cherry-pick <start-commit-id>..<end-commit-id>
git cherry-pick <start-commit-id>^..<end-commit-id>

前者表示把<start-commit-id>到<end-commit-id>之間(左開右閉,不包含start-commit-id)的提交cherry-pick到當前分支;
后者有"^"標志的表示把<start-commit-id>到<end-commit-id>之間(閉區間,包含start-commit-id)的提交cherry-pick到當前分支。
其中,<start-commit-id>到<end-commit-id>只需要commit-id的前6位即可,并且<start-commit-id>在時間上必須早于<end-commit-id>
注:以上合并,需要手動push代碼。

以上內容總結如下:

1.git checkout master            //此操作需要切換到master分支  

2.git pull

3.git cherry-pick  xxxxxx
 
4.git status 
 
5.編譯提交等

原文鏈接:https://www.cnblogs.com/chenyablog/p/8484556.html

欄目分類
最近更新