Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge two branches and, automatically, ignore specific files/folders?

I have a MEAN stack project separated into two branches: Ionic and Node.

The Ionic branch have all Ionic related files/folder. The front-end is created here to serve mobiles and web devices. But the code for web devices from this branch is not hosted anywhere.

The Node branch have server related files/folder. This branch will be uploaded to host the application end-points and will need to serve a public front-end folder. The front-end folder comes from the Ionic branch.

I've read this post about spliting a commit into separate commits, so we can ignore one of them. This don't solve the problem because I have lots of files and folders that should not merge and would be very hard to separate them all in each and every merge. I need only the front-end/public/www folder to merge into the Node branch.

I also read about this, this, this and a lot more relevant questions on Stack and articles on the internet, but none of them could address my issue.

We have a Node and an Ionic branch. The Node branch need to have only specific files and folders from the Ionic branch. How can we do that?

Appendixes

Branch Node example:

¬ node_modules
¬ routes
¬ www
¬ files/etc

Ionic Node example:

¬ node_modules //this should not merge into Node
¬ hooks        //this should not merge into Node
¬ resources    //this should not merge into Node
¬ www          //MERGE THIS
¬ files/etc    //some should merge, some should not.
like image 507
Rodmentou Avatar asked Dec 05 '15 14:12

Rodmentou


People also ask

How do I merge two branches automatically?

All repositories in a project can inherit or override the branching model, including automatic branch merging. To enable automatic branch merging for all repositories in a project (requires project admin permission): Go to Project settings > Branches. Under Automatic merging, select the On status and then select Save.

How do I merge folders from one branch to another?

Get the commit git cherry-pick -n <commit> Unstage everything git reset HEAD Stage the modifications you want to keep git add <path> Make the work tree match the index # (do this from the top level of the repo) git checkout . Done!

How do you automatic merge failed fix conflicts and then commit the result?

CONFLICT (content): Merge conflict in <fileName> Automatic merge failed; fix conflicts and then commit the result. This type of conflict can be resolved either by manually fixing all the merge conflict for each file OR using git reset ––hard (resets repository in order to back out of merge conflict situation).


1 Answers

This is from top of my head so it is only an idea to try out.
If I understand correctly you want to selectivly merge ionic onto node

git checkout node
git checkout -b temp
git checkout -p ionic -- www
# solve merge conflicts
# git add or git add -p (interactive per diff adding)
git checkout -p ionic -- files/etc

git checkout -p and git add -p should give you interactive option of adding and checking out paths/files/parts of files.

git checkout --help
-p --patch Interactively select hunks in the difference between the (or the index, if unspecified) and the working tree. The chosen hunks are then applied in reverse to the working tree (and if a was specified, the index).

This means that you can use git checkout -p to selectively discard edits from your current working tree. See the “Interactive Mode” section of git-add(1) to learn how to operate the --patch mode.

like image 63
edin-m Avatar answered Oct 16 '22 02:10

edin-m