使我的开发分支的提示成为我的主分支的新提示

Make the tip of my development branch the new tip of my master branch

我找到了 this and this。但是好像这两个都是把development分支的commit全部变成master分支的commit

如果我只想说“现在我的开发分支的尖端应该成为主分支的新尖端,即两个分支之间最后一个共同提交的下一个主分支提交”。

所以基本上是一个无条件的合并,所有的冲突都被忽略,有利于 tip 开发提交。

记住这是我自己的项目,没有其他人参与。

编辑

我尝试了 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操作

对此必须有一个简单的答案,我不敢相信我是第一个想要这样做的人!

我想你只是想要

git checkout master
git cherry-pick dev

其中 dev 是您的开发分支的名称。这使得 dev 尖端的提交引入的更改(而不是同一分支中任何先前提交的更改)成为 master 尖端的新提交。

我想你想描述的是这个。您从 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)

不仅如此,您还希望 MERGEmain 置于 dev.[=33= 完全相同的状态]

答案分为两部分。首先,您需要擦除 main 上的所有内容,回到分歧点:

% git switch main 
% git reset --hard $(git merge-base main dev)

现在进行合并。 Git 将尝试执行 fast-forward,这不是您想要的(您说过您不希望 main 变得与 dev 相同);所以要防止它:

% git merge --no-ff dev

急! main 上的最后一次提交,即您刚刚创建的合并提交,与 dev 上的最后一次提交 相同。原因是合并是自分歧点以来两个分支上所有更改的组合。但是自分歧点以来,main 没有 变化——因为我们在第一步中删除了它们。因此,此合并提交执行所有且仅执行自分歧点以来对 dev 所做的更改,这正是您所要求的(如果我理解正确的话)。