我目前正在努力將 2 個長期分歧的分支feature/A和feature/B一個專案重新組合在一起。在此期間,他們積累了許多相互矛盾的變化。在另一個之上重新建立一個基礎是不可行的,因為發生了很多變化。
因此,我迭代地feature/B將一個提交重新設定為更接近feature/A. 我正在使用一個名為的分支feature/rebase-target來跟蹤feature/A我當前feature/B基于的提交。我的作業流程基本上是:
git checkout feature/rebase-target && git rebase <sha-1 of the next commit towards feature/A head>git checkout feature/B && git rebase feature/rebase-target- 修復沖突并繼續變基直到完成
- 通過查看日志手動找到下一個 sha-1
feature/A
如何feature/A根據 的當前位置自動搜索更接近頭部的一次提交的 sha-1 feature/rebase-target?
uj5u.com熱心網友回復:
你可以這樣做:
next_target=$(git rev-list feature/rebase-target..feature/A | tail -n1) &&
git branch -f feature/rebase-target "$next_target"
這假設歷史是線性的。如果您在通往 的分支中有合并feature/A,請添加--first-parent.
請注意,rev-list --reverse -1這不起作用,因為這將首先將正常串列限制為一次提交,然后反轉輸出(如果只列出一個則沒有區別)。
進一步注意,在您的第 1 步中,您不必checkout遵循rebase(如果我正確理解情況,這是一個快進);你可以git branch -f改用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/488199.html
下一篇:Git不使用全域組態檔中的用戶
