Answer the question
In order to leave comments, you need to log in
How to commit changes to 2 different branches?
Hello, in general, subject.
There are 2 branches: master and client, where the first one contains the title working version of the project, and the client branch contains the same project but with user changes (a different color palette, renamed blocks, modified pages, etc.). In general, client is master plus any add-ons added by the user to the project.
At some stage, it becomes necessary to change the behavior of the entire project (in both master and client branches), while not merging client changes into the master branch.
As a result, the question is the following, what do I need to do in order to, for example, change the rest-api.php file in both branches, while leaving all other files in these branches untouched (so that index.php and other files for the master branch remain the same as was earlier, and for the client branch, index.php and other files would be with client add-ons, while rest-api.php would change in both branches)
It is worth clearing the HEAD for both branches, adding all new changes to stash and then sequentially switching in each of the branches and commit the changes?
If it does not make it difficult to write a sequence of commands.
Ps Or is it worth creating a new branch from the master to make changes to the necessary file and merge the new branch with client and master?
Thank you.
Answer the question
In order to leave comments, you need to log in
commit the changes in the rest-api.php file, copy the commit hash, switch to the target branch (client) and executegit cherry-pick %ХЕШ_КОММИТА%
Cheripiki is, of course, convenient, but can lead to unpleasant consequences. This is, firstly, duplication of commits, and secondly, if you forget to sketch something, then your client will stop working and you will figure out what's what for a long time.
1. If your client branch is just an improvement on the master branch, then you can rebase and move the client to the top of master. This changes the story, so it's not for everyone, but if you work with the repository alone, then it's a completely normal solution (the story will be beautiful).
2. So you don’t need to merge client into master, but on the contrary, merge master into client and it will be exactly what you need.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question