Git将功能分支签出到先前的提交并反映其他开发人员代码中的更改

问题描述 投票:1回答:1

正在开发的项目有几个远程开发人员。

正在制作一项新功能,让我们说featureBranch。现在其他开发人员分别在分支机构dev_1dev_2上。他们取消了featureBranch并更新了他们的代码,并开始研究它,并在各自的分支机构上将他们的代码推送到遥控器上几天。

现在决定featureBranch代码必须恢复到先前的提交而不会丢失更改。因此,在featureBranch上工作的开发人员执行了之前工作提交的checkout并创建了一个单独的分支,我们称之为featureRevert。现在开发人员已经要求我们将我们过去几天工作的变化整合到这个featureRevert中。

是否有任何方法可以做到这一点,而不必手动整合变化后,从featureRevert创建我们自己的分支,因为从我知道拉入dev_1dev_2简单地从featureRevert将无法工作,将不会覆盖featureBranch工作。

    Day 1:
    
   
    Developer working on featureBranch:
    
    git add -A
    git commit -m “Worked on feature day 1”
    
    git pull origin featureBranch
    
    git push origin featureBranch

    Developer working on dev_1:
    git add -A
    git commit -m “dev_1 changes”
    
    git pull origin featureBranch
    git push origin dev_1
    
    

    Developer working on dev_2:
    git add -A
    git commit -m “dev_2 changes”
    
    git pull origin featureBranch
    git push origin dev_2
    
    
    

    Day 2:
    
    Same as day 1
    
    
    
    .
    .
    .
    Day n (Decided to go back to previous commit on featureBranch to lets say day - 10):
    
    Developer working on featureBranch:
    
    git add -A
    git checkout -b featureRevert a9c146a09505837ec03b
    
    git push origin featureRevert

现在featureRevertfeatureBranch之间不存在任何代码应该从dev_1dev_2中删除。有没有办法用git做到这一点?

git
1个回答
0
投票

在这种情况下,你总是可以使用樱桃挑选。樱桃从dev_1dev_2挑选你想要的提交到featureRevert分支。

你可以在这里看到cherry-pick

也可以看到How to cherry pick multiple commits

如果您只想挑选一个文件的更改,而不是整个提交,您可以查看

How to cherry pick only changes for only one file, not the whole commit

© www.soinside.com 2019 - 2024. All rights reserved.