简体   繁体   中英

Git Merge: Remove unnecessary file/folder

git merge

我正在尝试将我的dev分支合并到master分支,但是我不想将某些文件/文件夹合并到master分支,因为Master上现在不需要了。

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

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

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 .gitattribute s settings. Otherwise, simply do a clean up commit that removes those unwanted files/directories before the merge.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM