简体   繁体   English

推送到远程服务器的GIT排除文件夹/文件

[英]GIT on push to a remote server exlude folders/files

Is there a way to exclude certain directories when using "git push remote_name". 有没有办法在使用“git push remote_name”时排除某些目录。

For example I have this folder/file structure in the repository: 例如,我在存储库中有这个文件夹/文件结构:

/applications/
/libs/
/themes/
/misc/
/index.php
/robots.txt
/sitemap.xml

when I am working locally I commit all the changes I do to any files/folders, but when I need to "push" everything out to the remote server repository I want to exclude certain files and folders, like the "/themes/" folder and robots.txt file 当我在本地工作时,我将所做的所有更改提交给任何文件/文件夹,但是当我需要将所有内容“推送”到远程服务器存储库时,我想要排除某些文件和文件夹,例如“/ themes /”文件夹和robots.txt文件

Summary : locally I "commit" everything but the moment I need to do a "git push" I want to be able to exclude folders and files. 总结 :本地我“提交”所有内容,但是当我需要执行“git push”时,我希望能够排除文件夹和文件。

I hope that makes sense. 我希望这是有道理的。

Thanks 谢谢

No, you can't do this with Git. 不,你不能用Git做到这一点。 In Git, each commit is treated as one atomic entity; 在Git中,每个提交都被视为一个原子实体; you can't pick and choose parts of a particular commit to push. 你无法挑选和选择推送的特定提交的部分。

If you want to break up your repository, such that some things are only tracked locally, and some pushed to the server, you should use separate repositories for each part, possibly linked together using Git submodules. 如果要分解存储库,以便某些东西只在本地跟踪,而某些东西被推送到服务器,则应为每个部分使用单独的存储库,可能使用Git子模块链接在一起。

You should keep a separate branch which matches what you want to have on the remote repository. 您应该保留一个单独的分支,该分支与您希望在远程存储库上拥有的分支相匹配。 Eg work on master, switch to my-public-branch, cherry-pick/merge/rebase off of master, push to remote, switch back to master for more work. 例如,在master上工作,切换到my-public-branch,从主人那里挑选/合并/重新关闭,推送到远程,切换回master以进行更多工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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