Jackson
Jackson

Reputation: 1524

Git Merge: Remove unnecessary file/folder

git merge

I'm trying to merge my dev branch to master, but I don't want to merge some of the files/folders to master branch, because it is not needed now on Master.

Upvotes: 1

Views: 2007

Answers (3)

Philip Oakley
Philip Oakley

Reputation: 14071

You can use a similar trick (but in reverse) to that given in How to make Git preserve specific files while merging where you could .gitattribute the file, and then create a merge driver that simply removes its content.

This will depend on whether you want the file gone from the commit or an empty content to be still present. It also presumes that these are well known files that can be picked up by the .gitattributes settings. Otherwise, simply do a clean up commit that removes those unwanted files/directories before the merge.

Upvotes: 0

DexJ
DexJ

Reputation: 1264

guessing file you are talking about are committed already.

git rm yourfile.txt
git commit -m "remove yourfile.txt"

and then push your changes to branch

git push origin branch_name

and then merge with your master branch.

Note: for the directory use--> git rm -r somedirName

Upvotes: 1

Gabsii
Gabsii

Reputation: 456

Create a second branch for your git repository, then push your repository on the second one. Then delete the files you don't need on master and merge the second branch with master

Upvotes: 2

Related Questions