简体   繁体   English

Git樱桃摘旧提交

[英]Git cherry-pick old commit

I just encountered the following scenario: 我刚遇到以下情况:

Some commits in a branch [develop] (multiple people working on it) were causing issues and I wanted to copy them to a separate branch [feature1] so they could be fixed/added to (and the code removed from the current branch [develop]). 分支[develop]中的某些提交(正在工作的多个人)引起了问题,我想将它们复制到单独的分支[feature1]中,以便可以对其进行修复/添加(并将代码从当前分支[develop中删除])。 They had already been pushed to remote [origin/develop] quite a while ago. 他们早已被推送到远程[来源/开发]。

What I ended up doing was: 1. creating a separate branch [feature1] 2. deleting the code from the [develop] branch 我最终要做的是:1.创建一个单独的分支[feature1] 2.从[develop]分支中删除代码

I then realised that if someone else did a git merge [develop] (to bring in any new desired changes) whilst on [feature1], the deletions would get pulled through (and they would lose the code). 然后,我意识到,如果其他人在[feature1]上进行了git merge [develop](以进行任何新的所需更改),则删除操作将被删除(它们将丢失代码)。 But I needed to keep these historical commits. 但是我需要保留这些历史承诺。 I then therefore thought I could: 因此,我以为自己可以:

  1. merge in the deletion: git merge [develop] (whilst on [feature1]) 在删除中进行合并:git merge [develop](在[feature1]上比较详细)
  2. cherry-pick the hash of the old commits I wanted to keep. 挑选我想保留的旧提交的哈希值。

I then realised I could not do that (it was saying my local changes would get overwritten, even though there were no local changes). 然后,我意识到我做不到(这是说我的本地更改将被覆盖,即使没有本地更改也是如此)。 I presume this is because the old commits were dated as older than the deletion I had just merged in. 我认为这是因为旧提交的日期早于我刚刚合并的删除的日期。

There must be way of doing this, kind of like a cherry-pick force or something else! 一定有办法做到这一点,有点像只摘樱桃的力量! Any ideas what the best command would be for this scenario? 任何想法对于这种情况最好的命令是什么?

Thanks 谢谢

git merge -s ours

将创建合并历史记录而不合并任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM