我有一個A帶有已驗證作業狀態的應用程式版本提交的分支。還有一些N提交應用了一些可能不相關/破壞性的更改。其次是M提交,其目的是實作某些功能,但引入了其他可能不相關/破壞性的更改。我需要選擇和應用僅與引入的功能相關的更改,并擺脫那些不相關/可能破壞的更改。
因此,它看起來像:
A -> N... -> M... -> P...。
如何比較一組 M..到 的變化A?
類似問題:兩次提交之間的 Git diff 中間沒有一些提交
uj5u.com熱心網友回復:
我建議創建一個從 開始的分支A,并且只包含該M...范圍的提交。
您可以使用git rebase -i以下方法執行此操作:
# create a new branch from your current branch :
git checkout -b feature
# run :
git rebase -i <A>
# an editor opens : the instructions on what to do with this file are
# explained as comments at the bottom of the file
# in your case : remove all lines mentioning commits in
# the 'N...' and 'P...' ranges
# save and exit
您可能必須在此程序中修復沖突,但最終結果應該是:一個新分支,M...在A.
比較來自這個分支的提交A會更直接。
實際上,您可以git rebase選擇提交M...范圍的提交范圍:
- spot
<lastN>,第一個提交的父項的哈希值M..., - spot
<lastM>,最后一次提交的哈希值M... - 運行以下命令:
git branch feature <lastM>
git rebase --onto <A> <lastN> feature
如果您想確認您選擇了您期望的所有提交,您可以添加-i到git rebase命令中。
正如您在評論中所建議的那樣,M...在 頂部挑選每個提交<A>也是創建該分支的有效方法:
# to list the commits :
git rev-list <lastN>..<lastM>
# to use it in a cherry-pick command :
git checkout -b feature <A> # start from <A>
git cherry-pick $(git rev-list <lastN>..<lastM>)
所有三種方法都會給出相同的結果。
uj5u.com熱心網友回復:
git diff 應該能夠幫助你:
git diff commitA commitM
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/313213.html
標籤:混帐
