git 从 dev 分支合并到 master 到某个提交为止的所有提交

git merge from dev branch to master all commits upto a certain commit

我从我的主分支创建了一个新分支。在我的新分支中,我有一些提交 (A-B-C-D-E)。我想将提交 C 和之前的所有内容合并到 master 中。我知道我可以使用 cherrypick A、C 和 C。但是有没有办法告诉 git 包含 C 和之前的所有内容并合并到 master 中?

只是 运行 git 合并 <em>hash-of-desired-commit</em>.

事实上,这就是 git merge 实际工作的方式。 Git 不基于 分支 1 合并,而是基于 提交 。当您 运行 git 合并 <em>branch-name</em> 时,Git 将名称变成提交哈希, then 与散列合并。该名称唯一做的就是设置默认提交 message(例如,merge branch brmerge branch br into feature)。


1更准确的说,我这里的意思是分支名称。另请参阅 What exactly do we mean by "branch"? 当您指定提交哈希时,生成的合并包含提交图的一个子集,以及单词 branch also表示 提交图的某个子集 ,因此从这个意义上说,Git 确实合并了 "branches".

这里的问题是 branch 这个词本身被过度使用了,这使它失去了意义。你参加过每个人都叫布鲁斯的派对吗? "Hey, Bruce! Bruce told me to tell you that Bruce called Bruce to relay that Bruce wasn't going to be able to make it. Please tell this to Bruce, OK?"(哪个布鲁斯真的不会成功?)