git中cherry-pick命令的使用教程
git cherry-pick可以選擇某一個分支中的一個或幾個commit(s)來進行操作。例如,假設我們有個穩(wěn)定版本的分支,叫v2.0,另外還有個開發(fā)版本的分支v3.0,我們不能直接把兩個分支合并,這樣會導致穩(wěn)定版本混亂,但是又想增加一個v3.0中的功能到v2.0中,這里就可以使用cherry-pick了,其實也就是對已經(jīng)存在的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 的過程中出現(xiàn)了沖突
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 # 看哪些文件出現(xiàn)沖突
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
則執(zhí)行對應操作:
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一個區(qū)間的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>之間(閉區(qū)間,包含start-commit-id)的提交cherry-pick到當前分支。
其中,<start-commit-id>到<end-commit-id>只需要commit-id的前6位即可,并且<start-commit-id>在時間上必須早于<end-commit-id>
注:以上合并,需要手動push代碼。
以上內(nèi)容總結如下:
1.git checkout master //此操作需要切換到master分支 2.git pull 3.git cherry-pick xxxxxx 4.git status 5.編譯提交等
到此這篇關于git中cherry-pick命令的文章就介紹到這了。希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
使用 FFmpeg 命令拼接mp3音頻文件異常問題及解決方法
這篇文章主要介紹了使用 FFmpeg 命令拼接mp3音頻文件異常問題及解決方法,本文給大家介紹的非常詳細,對大家的工作或?qū)W習具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03cnpm不是內(nèi)部命令的解決方案:配置環(huán)境變量【推薦】
這篇文章主要介紹了cnpm不是內(nèi)部命令的解決方案:配置環(huán)境變量的相關知識,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-07-07在Visual Studio Code環(huán)境中使用SVN的方案
這篇文章主要介紹了在Visual Studio Code環(huán)境中使用SVN的方案,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-04-04antd通過 filterDropdown 自定義按某天時間搜索功能
這篇文章主要介紹了antd通過 filterDropdown 自定義按某天時間搜索功能,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-08-08