[英]Make the tip of my development branch the new tip of my master branch
我找到了這個和這個。 但似乎這兩者都將 development 分支中的所有提交都變成了 master 分支上的提交。
如果我只想說“現在我的開發分支的尖端應該成為主分支的新尖端,即兩個分支之間最后一個共同提交的下一個主分支提交”怎么辦?
所以基本上是一個無條件的合並,所有的沖突都被忽略以支持尖端開發提交。
請記住,這是我自己的項目,沒有其他人參與。
編輯
我嘗試了 chepner 的解決方案並得到了這個
(doc_indexer) mike@M17A:/.../doc_indexer$ git cherry-pick my_dev_branch
Auto-merging tests/basic_tests/test_indexing_task.py
CONFLICT (content): Merge conflict in tests/basic_tests/test_indexing_task.py
Auto-merging src/core/visual_log_table_classes.py
Auto-merging src/core/main_window_class.py
CONFLICT (content): Merge conflict in src/core/main_window_class.py
Auto-merging src/core/indexing_task_class.py
CONFLICT (content): Merge conflict in src/core/indexing_task_class.py
error: could not apply d777951... ATG. [... my commit messaage for the tip commit on the dev branch]
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'
...然后取消了 cherry-pick 操作。
必須有一個簡單的答案,我不敢相信我是第一個想要這樣做的人!
我想你想描述的是這個。 您從master
(我稱之為main
)分支development
(我稱之為dev
)。 好的,那你繼續在兩個分支上工作。 但是過了一會兒,你意識到你在main
上的所有工作都是錯誤的, dev
是正確的,你只想將dev
合並到main
中,就好像自分歧點以來main
上什么也沒發生一樣。 換句話說,從這個開始:
A -- B -- C -- D -- E -- F (main)
\
X -- Y -- Z (dev)
你要這個:
A -- B -- C ---------- MERGE (main)
\ /
X -- Y -- Z (dev)
不僅如此,您還希望MERGE
將main
放入與dev
完全相同的 state 中。
答案分為兩部分。 首先,您需要將main
上的所有內容擦除到分歧點:
% git switch main
% git reset --hard $(git merge-base main dev)
現在進行合並。 Git 將嘗試執行快進,這不是您想要的(您說過您不希望main
與dev
相同); 所以防止它:
% git merge --no-ff dev
急! main
上的最后一次提交,即您剛剛創建的合並提交,與dev
上的最后一次提交相同。 原因是合並是自分歧點以來兩個分支上所有更改的組合。 但是自分歧點以來, main
上沒有任何變化——因為我們在第一步中刪除了它們。 因此,此合並提交會執行所有且僅執行自分歧點以來對dev
所做的更改,這正是您所要求的(如果我理解正確的話)。
我想你只是想要
git checkout master
git cherry-pick dev
其中dev
是您的開發分支的名稱。 這使得dev
尖端的提交引入的更改(而不是同一分支中任何先前提交的更改)成為master
尖端的新提交。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.