1

At our company we have alpha and beta, when we are about to release a new version we do a git merge alpha (while on beta branch), so we merge all alpha into beta.

The problem with this approach is that we have some config files that shouldn't be merged into beta, that are alpha (and other development branches) only, but should not be git ignored either, nor belong to another repository because after all they do belong to that specific branch.

So, the "ideal" solution would be to have something like:

git merge alpha -commit-to-ignore

or just set the specific files to be ignored when and only when merging.

Not sure if those options even exist, or if its the best approach.

1 Answer 1

1

If the changes in config files in branch alpha and beta are mutually exclusive i.e. they would cause a conflict, then you can simply merge it using ours merge strategy

git merge -s ours alpha 

Otherwise, simplest solution would be to create a new branch from alpha. Delete the config files you don't want to merge, commit the changes and merge the new branch into beta. However, with this approach if you eventually merge beta into alpha, you'd loose the config files in alpha too in case of Fast-Forward Merge.

More preferable solution would be to create a separate commit in alpha which contains the config changes, now you can merge/rebase the rest of the branch into beta except that commit.

If the changes in config files is the latest commit, then you can easily do it as follows

git checkout -b temp_branch HEAD~1 git checkout beta git merge temp_branch 

If the commit lies somewhere in between then you need to rebase --onto to remove that particular commit, and then merge. To explain, let's say you have

>> git log --oneline 2c10ba8 latest commit 088a38e config commit c233f51 some other commit >> git checkout -b temp_branch # Now you need to remove 'config commit' with hash id 088a38e >> git rebase --onto c233f51 088a38e 2c10ba8 # resolve if any conflict occurs # Now your git log should look like shown below, with undesirable commit removed >> git log --oneline 2c10ba8 latest commit c233f51 some other commit >> git checkout beta >> git merge temp_branch 
Sign up to request clarification or add additional context in comments.

2 Comments

"More preferable solution would be to create a separate commit in alpha which contains the config changes, now you merge the rest of the branch into beta except that commit." <- how do you do that merge without that commit? :) When you do a git merge branchName git takes everything, that file included.
If all your undesirable changes are in single commit, then you can do it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.