簡體   English   中英

在合並到git的另一個分支時僅選擇提交范圍

[英]Picking only range of commits while merging into another branch in git

功能分支1

1
2
3 - this commit changed more than 1000 files
4
5
6 - this commit changed more than 1000 files
7
8
9
10

我正在並行處理另一個功能。 直到第10次提交,我才從功能分支1中提取所有代碼。

現在,由於第3次和第6次提交,執行git merge時有太多沖突。

因此,有可能在合並到feature-branch2時不進行第3次和第6次提交

或者有沒有辦法從9到1挑選提交(3和6除外)

還是可以像[9-7],[5-4],[2-1]那樣逐步進行

請建議

您可以嘗試在合並到目標分支之前,在源分支中刪除或還原不需要的提交。 為安全起見,您可能要從feature1創建一個新分支,並使用git revert撤消不需要的提交:

# from feature 1
git checkout -b feature1_a
git revert 3^..6
git push origin feature1_a

在您要還原的范圍內,用較早和較新提交的SHA-1哈希替換上面的36

然后,從feature1_a向目標分支發出拉取請求。

首先是一個明顯的假設:如果您要求刪除提交“ 3”和“ 6”,則您知道可以丟棄這些提交中的修改,而不僅僅是“丟棄它們,因為它們使我煩惱”。


您可以使用git rebase -i {1} (用圖中的提交1的哈希替換“ 1”)。

執行此命令將在文本編輯器中打開一個文件:

pick 2   commit message
pick 3   commit message
pick 4   commit message
pick 5   commit message
pick 6   commit message
pick 7   commit message
pick 8   commit message
pick 9   commit message
pick 10  commit message

# Rebase 31ae65d16..b31f500e4 onto 31ae65d16 (30 commands)
#
# Commands:
# p, pick <commit> = use commit
#   ...   instructions to edit the history above

在此文件中,刪除行“ 3”和“ 6”,然后保存並退出。

結果將是一個分支,具有除“ 3”和“ 6”之外的所有提交。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM