简体   繁体   English

如何删除从Git中的源代码派生而来的二进制文件,但仍部署到远程存储库?

[英]How can I remove binary files derived from source code in Git and yet still deploy to a remote repository?

Currently where I work we have the following set-up (for ASP.NET web-development) using Git for version control (which we are relatively new to): 目前,在我工作的地方,我们有以下设置(用于ASP.NET Web开发),使用Git进行版本控制(这是我们相对较新的版本):

A "development" server which is a remote server running IIS that is accessible on our internal network. 一个“开发”服务器,它是运行IIS的远程服务器,可以在我们的内部网络上访问该服务器。 This is where we deploy stable development website builds so they are viewable throughout our company. 我们在这里部署稳定的开发网站,以便在整个公司范围内都可以看到它们。 On this server we create a Git repository for each project (typically a website). 在此服务器上,我们为每个项目(通常是网站)创建一个Git存储库。

Developers will then pull this repository to their local machines and work on it locally, committing any changes locally and then finally pushing those changes to the remote repository (the development server) where they are merged into the master branch. 然后,开发人员将将此存储库拉到其本地计算机上并在本地进行处理,在本地提交所有更改,最后将这些更改推送到远程存储库(开发服务器)中,在此将它们合并到master分支中。

The problem we have is that when source code is built into assemblies (DLLs) then these are added to the local Git repository, cluttering it up with binary files that shouldn't really be there (since they can be derived from source). 我们遇到的问题是,当将源代码构建到程序集(DLL)中时,会将这些代码添加到本地Git存储库中,并用实际上不应该存在的二进制文件将其弄乱(因为它们可以从源代码派生)。 However, if we don't include the DLLs (ie. put them in .gitignore) then when we push changes to the remote repository the DLLs will be missing from the /bin folder and the site won't work. 但是,如果我们不包含这些DLL(即将它们放在.gitignore中),则当我们将更改推送到远程存储库时,/ bin文件夹中的DLL将丢失,并且该站点将无法工作。 The only way around this would be to rebuild the site on the development server after pushing changes. 解决此问题的唯一方法是在推送更改后在开发服务器上重建站点。

Is there any way around this? 有没有办法解决? Ideally we need a way to ignore the DLLs from our local repository yet still "push" them to the remote server? 理想情况下,我们需要一种方法来忽略本地存储库中的DLL,但仍将其“推送”到远程服务器? Or somehow trigger a build on the remote server when changes are pushed? 还是在推送更改时以某种方式触发远程服务器上的构建?

Sounds like you need to look into "continuous integration". 听起来您需要研究“持续集成”。 You can set up your build server to run a clean build each time someone commits or you can configure for certain times in the day. 您可以将构建服务器设置为每次有人提交时都运行干净的构建,或者可以配置一天中的特定时间。 You can also trigger a script to run if the build succeeds such as deploying to a test server. 如果构建成功(例如部署到测试服务器),您还可以触发脚本运行。 Plus you can get it to run unit tests and send an email to the team with any errors etc. 另外,您可以获取它来运行单元测试,并向任何错误发送电子邮件给团队。

I don't know how builds work in .net but my favourite CI server is jenkins. 我不知道构建如何在.net中工作,但我最喜欢的CI服务器是jenkins。 http://jenkins-ci.org/ http://jenkins-ci.org/

There are others eg cruise control http://cruisecontrol.sourceforge.net/ 还有其他功能,例如巡航控制http://cruisecontrol.sourceforge.net/

Both are free. 两者都是免费的。

You could opt for having two parallel branches: one would have only "clean" commits, and each time you make a commit which is to be pushed to the production machine, you switch to the "binary" branch, (re-)merge the "clean" branch into it, build, add the generated binary files, commit and push. 您可以选择具有两个并行分支:一个分支只有“干净”提交,并且每次进行要推送到生产机器的提交时,都切换到“二进制”分支,(重新)合并将其“干净”分支,构建,添加生成的二进制文件,提交并推送。

Another approach to consider might be to stop using Git for deployment and use a specialized tool like rsync to push your binaries to production. 可以考虑的另一种方法是停止使用Git进行部署,并使用rsync类的专用工具将二进制文件推送到生产环境。

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

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