. gitignore 为 PhoneGap/Cordova 3.0项目-我应该承诺什么?

我刚刚尝试创建一个新的 Phone Gap 3.0项目... ... 注意: 我是新的 phonegap。 不管怎样,我看到项目文件夹包含:

  • .cordova
  • merges
  • platforms
  • plugins
  • www

在尝试了 phonegap local run android之后,我在 platforms/android中看到了很多二进制/生成的文件。 这让我想知道,这个文件夹结构的哪些部分应该添加到我的 git 存储库。 通常,我认为提交二进制文件是极其糟糕的做法。 因此,我通常会向 .gitignore添加类似于 bin/obj/*.o*.pyc等模式,以避免使用那些只会产生合并冲突的东西来污染我的 git 存储库。

当然,应该在 git 中添加 www,但是项目的其他部分怎么办呢。它们在多大程度上是源代码的产品,在多大程度上是项目配置?

- 你是做什么的?-就算我是新来的,所以我不太明白这里有什么意义..。

29479 次浏览

The answer depends on wich platforms you're developing the phongap app, and if you're following the standard directory structure.

If your project directory structure is standard, then you can start from this gitignore and modify it for your needs.

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.

All generated files in the android subdirectory should be excluded too:

Android/bin/
Android/gen/
Android/assets/

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.

Expanding on @Jake Moshenko answer:

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/

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:

#!/bin/bash
textReset=$(tput sgr0)
textGreen=$(tput setaf 2)
message_info () {
echo "${textGreen}[my-app]${textReset} $1"
}


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).

Update: Bash Gist

This gist contains 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.

Update: Grunt Gist

Here is another gist which is a Grunt port of the above mentioned bash script. (Thanks to @obie for suggesting grunt).

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/cordova add platform

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.

This way, when a developer clone the repository, he/she will have to:

1.- Add the platforms: phonegap/cordova add platform "platform"

2.- Add the plugins: phonegap/cordova plugin add "plugin"

Hope this helps!

Regards.

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!

www/
.gradle/
build/
.tmp/
.temp/
coverage/
*.log
node_modules/
bower_components/

While it's somewhat personal preference, I went with this (for an android only project). Removing most, but keeping what's custom

ToonPlane/platforms/android/*
!ToonPlane/platforms/android/AndroidManifest.xml
ToonPlane/plugins/*
!ToonPlane/plugins/android.json
!ToonPlane/plugins/fetch.json