I've read about some tricks with merge in Git: merging public and private branches while while keeping certain files intact in both branches and others and not found a solution.
In my case I'm feeling need to do opposite merge strategy. In parallel development I have to keep some files same across the arbitrary branches. From other side I do not want to do squash or no-commit merge, while difference are significant and could break current state of testing branch.
What I want something like
git checkout testing
git merge config.xml -b development
or git merge config\*.xml -b development
I guess this is like git merge-files ...
command, but second file delivered from the branch, not from the filesystem. Is it possible? or may be there is a kind of workaround? submodules? attributes?
Thanks
We can use git checkout for far more than simply changing branches. If we supply it with a branch name and a file, we can replace a corrupted or broken file. Instead, if we want to pass some of the changed content we can use the --patch flag to manually merge an individual file.
To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.
No, merging does only affect one branch.
There are a couple things you can do.
One, you can cherry-pick the changes you want, which applies only a single commit. For example, if there's a change that only touches config.xml
, you can cherry-pick it with
$ git cherry-pick $COMMIT_ID_YOU_WANT
You could also just grab config.xml
from the development branch:
$ git checkout testing $ git checkout development -- config.xml
That'll get you the same version of config.xml
that exists in the development branch, but note that it won't pull in the history of changes to the file.
Basically you can all read after here: http://www.gelato.unsw.edu.au/archives/git/0701/37964.html
In short, if you just want to apply changes made by a certain range of commits (this can as well be only a single commit), made to only a subset of files then do:
git diff commit1..commit2 filepattern | git apply --index && git commit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With