0

I've started two weeks ago using Git. For now I do only commit and push. I did a mistake and I've created a branch. Now I have a file, say "main.js" that has important changes in both branches.

In general : I have master that is production, then the dev branch, and a hot fix branch. I've changed main.js in dev, then I must change it in hot fix to solve a bug, and I merge hot fix in master. Now master and dev has disalligned main.js. How to maintain a situation like that?

Edit : Maybe im using git completly wrong ... I do some practical examples :

master - main.js - created 01/01/2017

function main() { 
    start(); 
}

dev - main.js - modified 07/01/2017

function main() { 
    new_stuff_1();
    start(new_param);
    new_stuff_2();  
}

hotfix - main.js - modified 10/01/2017

function main() { 
    hotfix();
    start();
}

After all merges i hope to have :

function main() { 
        hotfix();
        new_stuff_1();
        start(new_param);
        new_stuff_2();  
    }
Daniele Ravizza
  • 111
  • 1
  • 12
  • Not my downvote, but it isn't clear what your exact problem is. Files become "disalligned" between branches all the time in Git, this is a normal thing. – Tim Biegeleisen Jan 31 '17 at 07:53
  • There isn't much of a question here. Just merge the branches back to their sources in the reverse order, making sure that the changes you want are being preserved, and you should be done with it. – Tim Biegeleisen Jan 31 '17 at 08:52

2 Answers2

0

When you are in hotfix branch, update the main.js file and commit those changes. Then checkout to dev branch.

git checkout dev

Merge your changes from hotfix into dev.

git merge hotfix

Bleh
  • 441
  • 3
  • 14
0

In your case, now that you have made your fix and merged it to master, you also have to merge your hotfix in the dev branch. this way you'll get to merge both your modification you've made on your main.js

here is a good document on how working with branches on git: http://nvie.com/posts/a-successful-git-branching-model/.