1

The project being worked on has several remote developers.

A new feature was being worked on lets say featureBranch. Now other developers are on branch dev_1 and dev_2 respectively. They took the pull of the featureBranch and updated their code and started working on it and pushed their code to the remote over a period of a few days on their respective branches.

Now it was decided that the featureBranch code had to be reverted to a previous commit without losing the changes. So the developer working on featureBranch did a checkout of a previous working commit and created a separate branch lets call it featureRevert. Now the developer has asked us to integrate our changes that we worked on the past few days into this featureRevert.

Is there any way to do this without having to manually integrate the changes after creating our own branches from featureRevert as from what I know taking a pull into dev_1 or dev_2 simply from featureRevert won't work and won't overwrite the featureBranch work.

    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

Now whatever code is not present in between the featureRevert and featureBranch should be removed from dev_1 and dev_2. Is there a way to do that using git?

Rikh
  • 4,078
  • 3
  • 15
  • 35
  • This line is not clear `Now other developers dev_1 are on branch dev_2`. What is `dev_1`? – Noor A Shuvo Mar 13 '19 at 06:01
  • @NoorAShuvo updated the question. I made a mistake in the grammar. – Rikh Mar 13 '19 at 06:02
  • In order to better understand your question, could you add equivalent of git commands you type? – Jérôme Pouiller Mar 13 '19 at 06:05
  • @Jezz This should be the flow of what happened. What I wanted to ask what should be done so that `dev_1` and `dev_2` branches can get the code from `featureRevert` into `dev_1` or `dev_2` without losing their changes and the code from `featureBranch` being removed. – Rikh Mar 13 '19 at 06:15

1 Answers1

0

You can always use cherry-pick in this situation. Cherry pick your desired commits from dev_1 and dev_2 into the featureRevert branch.

You can see here cherry-pick

Can see also How to cherry pick multiple commits

If you want to cherry pick only changes for only one file, not the whole commit you can look at

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

Noor A Shuvo
  • 2,639
  • 3
  • 23
  • 48
  • But won't that add all the code from that particular commit if i were to cherry pick `dev_1`, including the `featureBranch` changes that were integrated into `dev_1` branch? – Rikh Mar 13 '19 at 06:15
  • You can pick specific commit to cherry pick. – Noor A Shuvo Mar 13 '19 at 06:22
  • I get that, but will that only integrate the files that were modified? Or all the files that were present in that particular commit? – Rikh Mar 13 '19 at 06:23
  • All the files that were present in that commit. – Noor A Shuvo Mar 13 '19 at 06:31
  • So lets say there was a `file-A` in the `featureBranch`. That had been removed when the code was reverted to `featureRevert`. If the developer in branch `dev_1` had the `file-A` and if i were to cherry-pick a commit from `dev_1` into `featureRevert`. That will add the file again right? So that won't actually help me in this case. – Rikh Mar 13 '19 at 06:34
  • https://stackoverflow.com/questions/16068186/how-to-cherry-pick-only-changes-for-only-one-file-not-the-whole-commit/16068510 may work in your situation – Noor A Shuvo Mar 13 '19 at 06:40
  • @Rikh Have you got the solution to your problem? – Noor A Shuvo Mar 13 '19 at 10:41
  • Well cherry picking would be same as manually re-adding files etc. I want the changes that were removed on the `featureBranch` mentioned above when reverted to `featureRevert` to be automatically reflected. – Rikh Mar 14 '19 at 16:32