在 CakePHP 项目中使用 Git

发布于 2024-08-20 05:11:55 字数 341 浏览 3 评论 0原文

我使用 git 作为我的主要版本控制系统,并且最近开始在我的 CakePHP 项目中使用 git。这是我当前的 .gitignore 文件:

app/tmp
vendors/

与 cakephp git 存储库中使用的一样,但这在将项目部署到服务器时会给我带来更多工作,因为我必须进入并创建所有 app/tmp/ 子目录在它们正常工作之前必须手动操作。有没有办法将其设置为忽略这些文件夹上的内容,但仍将它们置于 git 控制之下,以便当我将存储库克隆到 hoted 目录中时它们会出现?

我在处理 git 索引时也遇到了重置问题,这导致我必须做比必要的更多的提交,对此还有什么想法吗?

I use git as my primary version control system, and have recently started using git on my CakePHP projects. This is my current .gitignore file:

app/tmp
vendors/

As used in the cakephp git repo, but this causes a bit more work for me when deploying the project to a server, because I have to go in and create all the app/tmp/ sub-directories by hand before they will work correctly. Is there a way to set it up to ignore the contents on these folders, but to still have them under git control so they appear when I clone the repo into the hoted directory?

I also have been having an issue with my git index being reset while I am working on it, which is causing me to have to do a lot more commits than should be necessary, any ideas on that also?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岛歌少女 2024-08-27 05:11:55

Git 仅存储文件,而不存储目录,因此您可以将隐藏文件添加到该目录中并提交它。

  1. 从 .gitignore 中删除 app/tmp/
  2. touch app/tmp/.keep
  3. git add app/tmp/.keep
  4. git commit
  5. 将 app/tmp/ 添加到 .gitignore

Git stores only files, not directories, so you can for example add a hidden file into that directory and commit it.

  1. Remove app/tmp/ from .gitignore
  2. touch app/tmp/.keep
  3. git add app/tmp/.keep
  4. git commit
  5. Add app/tmp/ to .gitignore
2024-08-27 05:11:55

正如前面提到的,git 只存储文件,而不存储目录。默认情况下,cake 的 .gitignore 文件会忽略 tmp 文件夹中的所有内容,以防止 tmp 文件添加到存储库中。

但是,您可以(并且应该)在创建项目后执行此操作:

cd /my/app
git add -f tmp

这将执行以下操作:

$ git status
# On branch master
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   tmp/cache/models/empty
#   new file:   tmp/cache/persistent/empty
#   new file:   tmp/cache/views/empty
#   new file:   tmp/logs/empty
#   new file:   tmp/sessions/empty
#   new file:   tmp/tests/empty

因此您的 tmp 文件夹结构已准备好提交,但 tmp 目录中的所有其他文件将(继续)被忽略。

As mentioned git only stores files, not directories. By default cake's .gitignore file ignores all contents in the tmp folder to prevent tmp files being added to your repository.

You can (and should) however do this after you create a project:

cd /my/app
git add -f tmp

which will do this:

$ git status
# On branch master
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   tmp/cache/models/empty
#   new file:   tmp/cache/persistent/empty
#   new file:   tmp/cache/views/empty
#   new file:   tmp/logs/empty
#   new file:   tmp/sessions/empty
#   new file:   tmp/tests/empty

As such your tmp folder structure is ready to be committed, but all other files in your tmp dir will (continue to) be ignored.

困倦 2024-08-27 05:11:55

我的 .gitignore 文件。

tmp/*
[Cc]onfig/core.php
[Cc]onfig/database.php

webroot/files/
webroot/img/photos/

!empty
.DS_Store

如果你注意到我有 !empty ,它可以让我免于在 SVN 之前创建 .keep 文件。最后,您还会看到我将此配置用于 [Cc] 指出的 cakePHP 1.x 和 2.x 项目。我设置了一些文件夹来存储用户文件,所以我也总是忽略它们。最后,.DS_Store 忽略了我的 MAC 为我的项目创建的缩略图视图。

My .gitignore file.

tmp/*
[Cc]onfig/core.php
[Cc]onfig/database.php

webroot/files/
webroot/img/photos/

!empty
.DS_Store

If you'll notice I have !empty which saves me from creating .keep files all over which is so SVN ago. Lastly you'll also see that I use this config for both cakePHP 1.x and 2.x projects noted by the [Cc]. I have some folders setup that I store user files in so I always ignore them as well. Finally the .DS_Store ignores my MAC created thumbnail views for my project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文