git PhoneGap/Cordova 3.0 项目的 .gitignore - 我应该提交什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17911204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.gitignore for PhoneGap/Cordova 3.0 projects - what should I commit?
提问by jonasfj
I just tried to create a new phonegap 3.0 project... Note: I'm new to phonegap. Anyways, I see the project folder contains:
我只是尝试创建一个新的 phonegap 3.0 项目... 注意:我是 phonegap 的新手。无论如何,我看到项目文件夹包含:
.cordova
merges
platforms
plugins
www
.cordova
merges
platforms
plugins
www
And having tried phonegap local run android
I see a lot of binary/generated files in platforms/android
.
This leaves me wondering, what parts of this folder structure should I add to my git repository.
Normally, I would consider it extremely poor practice to commit binary files.
Hence, I would normally add patterns like bin/
, obj/
, *.o
, *.pyc
etc. to .gitignore
to avoid polluting my git repository with things that only serves to create merge conflicts.
尝试后,phonegap local run android
我在platforms/android
. 这让我想知道,我应该将这个文件夹结构的哪些部分添加到我的 git 存储库中。通常,我认为提交二进制文件是非常糟糕的做法。因此,我通常会添加模式,如bin/
,obj/
,*.o
,*.pyc
等,以.gitignore
避免污染我的git仓库的东西,只有用于创建合并冲突。
Surely, www
should be added to git, but what about the other parts of the project. To what extend are they products of the source code, and to what extend are they project configuration?
当然,www
应该添加到 git 中,但是项目的其他部分呢。它们是源代码的产品,它们的项目配置是什么?
What do you do? Granted I'm new so I barely understand what makes sense here...
你做什么工作?当然,我是新手,所以我几乎不明白这里有什么意义......
采纳答案by Atropo
The answer depends on wich platforms you're developing the phongap app, and if you're following the standard directory structure.
答案取决于您开发 phongap 应用程序的平台,以及您是否遵循标准目录结构。
If your project directory structure is standard, then you can start from this gitignoreand modify it for your needs.
如果你的项目目录结构是标准的,那么你可以从这个gitignore开始,根据你的需要修改它。
On a rule of thumb you've to exclude all generated files like the bin/
and gen/
directories.
If you're developing an Android version of your app you should exclude build files too like *.apk
.
根据经验,您必须排除所有生成的文件,如bin/
和gen/
目录。如果您正在开发应用程序的 Android 版本,则应该排除构建文件,例如*.apk
.
All generated files in the android
subdirectory should be excluded too:
android
子目录中所有生成的文件也应该被排除:
Android/bin/
Android/gen/
Android/assets/
回答by Jonathan Dixon
Expanding on @Jake Moshenko answer:
扩展@Jake Moshenko 的回答:
I like the idea of omitting the platforms
directory. In fact, I am am able to exclude both the plugins
and platforms
directories. A good starting point for the .gitignore
:
我喜欢省略platforms
目录的想法。事实上,我能够排除plugins
和platforms
目录。一个很好的起点.gitignore
:
platforms/
plugins/
The problem with this is that clean copy of the repo must be initialized before you can actually work with it. It may make sense to create an init script such as:
这样做的问题是,必须先初始化 repo 的干净副本,然后才能实际使用它。创建一个初始化脚本可能是有意义的,例如:
#!/bin/bash
textReset=$(tput sgr0)
textGreen=$(tput setaf 2)
message_info () {
echo "${textGreen}[my-app]${textReset} "
}
message_info "Creating necessary directories..."
mkdir plugins
mkdir platforms
message_info "Adding platforms..."
# If using cordova, change to: cordova platform add android
phonegap build android
phonegap build ios
message_info "Adding plugins..."
# If using cordova, change to: cordova plugin add
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git
A caveat to this approach is that it makes it a little more challenging to customize the platform specific app code/config outside of what's supported by phonegap/cordova (i.e. screen orientation support).
这种方法的一个警告是,在 phonegap/cordova 支持的内容(即屏幕方向支持)之外自定义平台特定的应用程序代码/配置会更具挑战性。
Update: Bash Gist
更新:Bash 要点
This gistcontains a more complete script for handling a project that does not commit the plugins
and platforms
directories. It provides a mechanism for copying the icons and splashscreen images from www to the platform directories (for iOS and Android), installing plugins, and handling platform specific files that should be added to version control.
这个要点包含一个更完整的脚本,用于处理不提交plugins
和platforms
目录的项目。它提供了一种机制,用于将图标和闪屏图像从 www 复制到平台目录(适用于 iOS 和 Android)、安装插件以及处理应添加到版本控制中的特定于平台的文件。
Update: Grunt Gist
更新:咕噜咕噜
Here is another gistwhich is a Grunt port of the above mentioned bash script. (Thanks to @obie for suggesting grunt).
这是另一个要点,它是上述 bash 脚本的 Grunt 端口。(感谢@obie 建议咕噜声)。
回答by Jake Moshenko
So I just figured this out through trial and error. The platforms
directory can be omitted if you are using phonegap local or remote build, as it is generated on the fly. All of the other folders, including the hidden folder .cordova
are required.
所以我只是通过反复试验来解决这个问题。platforms
如果您使用 phonegap 本地或远程构建,则可以省略该目录,因为它是动态生成的。所有其他文件夹,包括隐藏文件夹.cordova
都是必需的。
回答by nespapu
I just wanted to leave here my experience with this issue and the approach we finally followed.
我只是想在这里留下我在这个问题上的经验以及我们最终遵循的方法。
In our phonegap project we started to commit all files less the folder /platform using .gitignore file. We thought this way, when the developer cloned the repository the only action remaining to do would be to execute:
在我们的 phonegap 项目中,我们开始使用 .gitignore 文件提交除文件夹 /platform 之外的所有文件。我们是这样想的,当开发人员克隆存储库时,剩下的唯一操作就是执行:
phonegap/cordova add platform
phonegap/cordova 添加平台
But it wasn't. Once the platform was added and we tried to compile, an error appeared and the app didn't install in the device.
但事实并非如此。添加平台并尝试编译后,出现错误并且应用程序未安装在设备中。
Looking the logs, we got some hits that this error was due to plugins. So we decided to reinstall all the plugins we was using in the project and voilá the app run correctly.
查看日志,我们发现此错误是由插件引起的。所以我们决定重新安装我们在项目中使用的所有插件,然后应用程序正常运行。
So my advice is to save in the repository all the content less the folders platform and plugins. Create and upload to repository a file README with a list of plugins used in the project.
所以我的建议是将所有内容保存在存储库中,而不是文件夹平台和插件。创建一个文件 README 并将其上传到存储库,其中包含项目中使用的插件列表。
This way, when a developer clone the repository, he/she will have to:
这样,当开发人员克隆存储库时,他/她将必须:
1.- Add the platforms: phonegap/cordova add platform "platform"
1.- 添加平台:phonegap/cordova 添加平台“平台”
2.- Add the plugins: phonegap/cordova plugin add "plugin"
2.- 添加插件:phonegap/cordova 插件添加“插件”
Hope this helps!
希望这可以帮助!
Regards.
问候。
回答by Helzgate
A lot of this stuff is old and doesn't really apply to the latest version of Apache Cordova. I'm using Apache Cordova 5.1.1 and this .gitignore allows me to still customize with custom icons etc while blocking all the stuff we don't need to version for both Android and IOS. Yes .gradle is used so don't remove it!
很多这些东西都是旧的,并不真正适用于最新版本的 Apache Cordova。我正在使用 Apache Cordova 5.1.1 并且这个 .gitignore 允许我仍然使用自定义图标等进行自定义,同时阻止我们不需要为 Android 和 IOS 版本化的所有内容。是的 .gradle 已使用,所以不要删除它!
www/
.gradle/
build/
.tmp/
.temp/
coverage/
*.log
node_modules/
bower_components/
回答by Funkodebat
While it's somewhat personal preference, I went with this (for an android only project). Removing most, but keeping what's custom
虽然这有点个人偏好,但我选择了这个(仅适用于 android 项目)。删除大部分,但保留自定义内容
ToonPlane/platforms/android/*
!ToonPlane/platforms/android/AndroidManifest.xml
ToonPlane/plugins/*
!ToonPlane/plugins/android.json
!ToonPlane/plugins/fetch.json