简体   繁体   English

如何仅将某些目录或文件推送到远程? 在git中

[英]how to push to a remote only some directories or files? in git

I'm using heroku to develop a Django app and they use git to push the code. 我正在使用heroku开发Django应用,他们使用git来推送代码。 My problem is that they need this file structure: 我的问题是他们需要以下文件结构:

heroku_project/
     requirements.txt (this a pip requirements file)
     procfile (this file tell heroku how to run your app)
     django_project (the project itself)
     lib
     bin
     build
     lib (these 4 folders belong to my python virtual env)

So i have to have my git initialised on this folder so this means that there are this additional files: 所以我必须在这个文件夹上初始化我的git,所以这意味着还有这些其他文件:

heroku_Project/
     .gitignore
     .git

According to their instructions inside .gitignore there should be these lines: 根据他们.gitignore 的说明 ,应该有以下.gitignore行:

bin
build
include
lib
.Python
*.pyc

The problem is that I want to track those virtual env folders, because sometimes I install python only for testing and I discard them later, or I make experimental changes on them and I wish I could undo those changes using git, my question is how can i track these folders so I need to remove them from the .gitignore . 问题是我想跟踪那些虚拟的env文件夹,因为有时我只安装python进行测试,以后再丢弃它们,或者对它们进行实验性更改,希望我可以使用git撤消那些更改,我的问题是如何我跟踪这些文件夹,所以我需要从.gitignore删除它们。 The problem is when i do 问题是我什么时候做

git push heroku master

As this will push those folders and we don't want that, so how I can selectively push files and directories? 由于这将推送这些文件夹,而我们不希望这样做,那么如何有选择地推送文件和目录? Or what kind of work flow would you use to solve this problem? 或者您将使用哪种工作流程来解决此问题?

Thanks 谢谢

First, if you're doing active development in Heroku then you may be dead in the water. 首先,如果您在Heroku中进行积极开发,那么您可能会死在水中。 But if your doing development on your local machine - branches may be able to help you out. 但是,如果您在本地计算机上进行开发,则分支机构可能会为您提供帮助。

My advice to you would be to create a separate branch for deploying code to heroku. 我对您的建议是创建一个单独的分支,用于将代码部署到heroku。 In this scenario you could use the master branch for active development, and keep those virtual environment folders in there - and have a separate branch (say, "production") for deploying the code to heroku. 在这种情况下,您可以使用master分支进行主动开发,并将这些虚拟环境文件夹保留在其中-并具有一个单独的分支(例如“生产”),用于将代码部署到heroku。

Whenever you're ready to release a new version of your code, you should switch over to the production branch, merge in the changes from master, delete those virtual environment folders, then push to Heroku. 每当准备发布新版本的代码时,都应切换到生产分支,合并master中的更改,删除这些虚拟环境文件夹,然后推送到Heroku。 In practice, that command sequence will look something like this. 实际上,该命令序列将如下所示。

$ git checkout production
$ git merge master
$ rm -Rf bin build include lib .Python *.pyc
$ git commit -a -m "Cleanup for production."
$ git push heroku production

That seems as though it will be the best working solution. 看来这将是最佳的解决方案。 Some vectors you may want to look into on your own: 您可能需要自己研究一些向量:

  • Ways to automate the process of deleting the files via shell scripts and git hooks. 通过shell脚本和git挂钩自动删除文件的过程。
  • To make sure that Heroku can use a branch other than "master" for running code (I would think that it should be able to). 为了确保Heroku可以使用除“ master”之外的其他分支来运行代码(我认为应该可以)。
  • To see if it may be possible to use different .gitignore files in different branches, and if so - whether or not that will remove the cleanup process of deleting those files manually. 查看是否有可能在不同的分支中使用不同的.gitignore文件,以及是否这样做-是否将删除手动删除这些文件的清理过程。

Hope this helps! 希望这可以帮助!

Why don't you try virtualenvwrapper ? 您为什么不尝试virtualenvwrapper It separates the virtualenv from your development environment. 它将virtualenv与您的开发环境分开。 Typical scenario is that you work on one virtualenv, let's say "main_env". 典型的场景是您在一个virtualenv上工作,比如说“ main_env”。

 mkvirtualenv main_env

And when you need another one for testing, you can do 当您需要另一个进行测试时,您可以

mkvirtualenv test_env

and you can switch between them with one command: workon [name] . 您可以使用一个命令在它们之间切换: workon [name] You really shouldn't keep those files in git. 您真的不应该将这些文件保存在git中。 They're simply not related to project. 它们根本与项目无关。 And thanks to virtualenwrapper, you don't need git to switch between those virtual environments. 多亏了virtualenwrapper,您无需git即可在这些虚拟环境之间进行切换。

If you insist on keeping them, well, you can simply NOT stage them in git. 如果您坚持要保留它们,那么,您可以简单地不要在git中暂存它们。 If you don't add a file/folder with git add , it won't be sent to the server. 如果您不使用git add文件/文件夹,则不会将其发送到服务器。

暂无
暂无

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

相关问题 我如何将不同Django目录中的git commits推送到GitHub,而不必继续进行拉合并? - How do I push git commits in different Django directories to GitHub without having to keep doing pull merges? : [remote denied] master -> master (pre-receive hook denied) 错误:未能将一些参考推送到 'https.//git.heroku.com/stark-dawn-54447.git' - ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'https://git.heroku.com/stark-dawn-54447.git' VPS Git服务器中的Git推送错误(本地到远程)? - Git Push Error ( Local to Remote ) in VPS Git Server? Heroku在git push上删除文件? - Heroku deleting files upon git push? Git-在ec2上设置远程存储库并进行初始推送 - Git - setting up a remote repository on ec2 and doing an initial push Django-无法将一些引用发送到git@heroku.com - Django - failed to push some refs to git@heroku.com 如何将文件上传到 Django 中的任意目录? - How to upload files onto arbitrary directories in Django? 错误:无法将一些引用推送到'git@heroku.com:dry-plains-3718.git' - error: failed to push some refs to 'git@heroku.com:dry-plains-3718.git' heroku 错误:“无法将一些参考推送到‘https://git.heroku.com/pacific-refuge-35090.git’ - heroku error: "failed to push some refs to 'https://git.heroku.com/pacific-refuge-35090.git' 如何将git子模块推送到AWS Elastic Beanstalk? - How to push a git submodule to AWS Elastic Beanstalk?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM