【问题标题】:What folders should be git ignored in React Native project?在 React Native 项目中应该忽略哪些文件夹?
【发布时间】:2015-05-31 10:34:24
【问题描述】:

我在玩Facebook/React Native,当我运行git init 时,我不知道应该忽略什么应该忽略node_modules 文件夹,

我应该提交所有 iOS 文件夹吗?

谢谢

【问题讨论】:

    标签: reactjs react-native


    【解决方案1】:

    当你启动一个新项目时,React Native CLI 会创建一个.gitignore 文件:

    react-native init <ProjectName>
    

    它涵盖了所有应该/可以忽略的基础知识。

    来源:https://github.com/facebook/react-native/blob/master/template/_gitignore

    【讨论】:

    • 奇怪,它从来没有为我创建过那个文件。
    • 连我都找不到。我计划创建一些示例存储库,我可以在其中上传我的反应原生尝试......但我不确定要上传什么
    • 请注意,一些文本编辑器会隐藏以.开头的文件
    • 另请注意,react-native 与 react 不同。
    【解决方案2】:

    gitignore.io 建议 react-native 使用以下 .gitignore 文件:

    https://www.gitignore.io/api/reactnative创建

    ### ReactNative ###
    # React Native Stack Base
    ### ReactNative.Xcode Stack ###
    # Xcode
    #
    # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
    
    ## Build generated
    build/
    DerivedData/
    
    ## Various settings
    *.pbxuser
    !default.pbxuser
    *.mode1v3
    !default.mode1v3
    *.mode2v3
    !default.mode2v3
    *.perspectivev3
    !default.perspectivev3
    xcuserdata/
    
    ## Other
    *.moved-aside
    *.xccheckout
    *.xcscmblueprint
    
    ### ReactNative.Node Stack ###
    # Logs
    logs
    *.log
    npm-debug.log*
    yarn-debug.log*
    yarn-error.log*
    
    # Runtime data
    pids
    *.pid
    *.seed
    *.pid.lock
    
    # Directory for instrumented libs generated by jscoverage/JSCover
    lib-cov
    
    # Coverage directory used by tools like istanbul
    coverage
    
    # nyc test coverage
    .nyc_output
    
    # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
    .grunt
    
    # Bower dependency directory (https://bower.io/)
    bower_components
    
    # node-waf configuration
    .lock-wscript
    
    # Compiled binary addons (http://nodejs.org/api/addons.html)
    build/Release
    
    # Dependency directories
    node_modules/
    jspm_packages/
    
    # Typescript v1 declaration files
    typings/
    
    # Optional npm cache directory
    .npm
    
    # Optional eslint cache
    .eslintcache
    
    # Optional REPL history
    .node_repl_history
    
    # Output of 'npm pack'
    *.tgz
    
    # Yarn Integrity file
    .yarn-integrity
    
    # dotenv environment variables file
    .env
    
    
    ### ReactNative.Buck Stack ###
    buck-out/
    .buckconfig.local
    .buckd/
    .buckversion
    .fakebuckversion
    
    ### ReactNative.macOS Stack ###
    *.DS_Store
    .AppleDouble
    .LSOverride
    
    # Icon must end with two \r
    Icon
    
    
    # Thumbnails
    ._*
    
    # Files that might appear in the root of a volume
    .DocumentRevisions-V100
    .fseventsd
    .Spotlight-V100
    .TemporaryItems
    .Trashes
    .VolumeIcon.icns
    .com.apple.timemachine.donotpresent
    
    # Directories potentially created on remote AFP share
    .AppleDB
    .AppleDesktop
    Network Trash Folder
    Temporary Items
    .apdisk
    
    ### ReactNative.Gradle Stack ###
    .gradle
    **/build/
    
    # Ignore Gradle GUI config
    gradle-app.setting
    
    # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
    !gradle-wrapper.jar
    
    # Cache of project
    .gradletasknamecache
    
    # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
    # gradle/wrapper/gradle-wrapper.properties
    
    ### ReactNative.Android Stack ###
    # Built application files
    *.apk
    *.ap_
    
    # Files for the ART/Dalvik VM
    *.dex
    
    # Java class files
    *.class
    
    # Generated files
    bin/
    gen/
    out/
    
    # Gradle files
    .gradle/
    
    # Local configuration file (sdk path, etc)
    local.properties
    
    # Proguard folder generated by Eclipse
    proguard/
    
    # Log Files
    
    # Android Studio Navigation editor temp files
    .navigation/
    
    # Android Studio captures folder
    captures/
    
    # Intellij
    *.iml
    .idea/workspace.xml
    .idea/tasks.xml
    .idea/gradle.xml
    .idea/dictionaries
    .idea/libraries
    
    # External native build folder generated in Android Studio 2.2 and later
    .externalNativeBuild
    
    # Freeline
    freeline.py
    freeline/
    freeline_project_description.json
    
    ### ReactNative.Linux Stack ###
    *~
    
    # temporary files which can be created if a process still has a handle open of a deleted file
    .fuse_hidden*
    
    # KDE directory preferences
    .directory
    
    # Linux trash folder which might appear on any partition or disk
    .Trash-*
    
    # .nfs files are created when an open file is removed but is still being accessed
    .nfs*
    
    # End of https://www.gitignore.io/api/reactnative
    

    【讨论】:

      【解决方案3】:

      我们建议使用 .gitignore:react-native/Examples/SampleApp/.gitignore

      它会忽略用户特定的 Xcode 文件和 node_modules 目录。

      【讨论】:

      • 这是一个好的开始,但不包括 android 所需的内容。 cli 生成的 .gitignore 包含 ios 和 android。
      • 链接已失效(这是我们不喜欢仅链接答案的原因之一:)
      【解决方案4】:

      这是一个相关问题:What should Xcode 6 gitignore file include?

      可以分为三类:

      1. IDE(Webstorm,Xcode) 配置 文件,如:.idea/,ios/ProjectName.xcodeproj/xcuserdata
      2. 版本控制工具(git,svn)文件,如:.git
      3. 其他文件,例如.DS_Store是OSX dir配置文件

      我的答案是经过实践检验的:

      ### SVN template
      .svn/
      ### Xcode template
      # Xcode
      #
      # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
      
      ## Build generated
      build/
      DerivedData/
      
      ## Various settings
      *.pbxuser
      !default.pbxuser
      *.mode1v3
      !default.mode1v3
      *.mode2v3
      !default.mode2v3
      *.perspectivev3
      !default.perspectivev3
      xcuserdata/
      
      ## Other
      *.moved-aside
      *.xccheckout
      *.xcscmblueprint
      ### JetBrains template
      # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
      # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
      
      # User-specific stuff:
      .idea/workspace.xml
      .idea/tasks.xml
      .idea/dictionaries
      .idea/vcs.xml
      .idea/jsLibraryMappings.xml
      
      # Sensitive or high-churn files:
      .idea/dataSources.ids
      .idea/dataSources.xml
      .idea/dataSources.local.xml
      .idea/sqlDataSources.xml
      .idea/dynamic.xml
      .idea/uiDesigner.xml
      
      # Gradle:
      .idea/gradle.xml
      .idea/libraries
      .idea
      
      # Mongo Explorer plugin:
      .idea/mongoSettings.xml
      
      ## File-based project format:
      *.iws
      
      ## Plugin-specific files:
      
      # IntelliJ
      /out/
      
      # mpeltonen/sbt-idea plugin
      .idea_modules/
      
      # JIRA plugin
      atlassian-ide-plugin.xml
      # Crashlytics plugin (for Android Studio and IntelliJ)
      com_crashlytics_export_strings.xml
      crashlytics.properties
      crashlytics-build.properties
      fabric.properties
      ### TortoiseGit template
      # Project-level settings
      /.tgitconfig
      
      *.swp
      
      # node_modules/,Xcode and Webstorm will spend lots of time for indexing this dir
      node_modules/
      
      # ios/Pods,
      ios/Pods/
      
      # OS X temporary files that should never be committed
      .DS_Store
      src/components/.DS_Store
      
      # user personal info,for example debug info
      ios/ProjectName.xcodeproj/project.xcworkspace/
      ios/ProjectName.xcodeproj/xcuserdata
      
      # Podfile versions
      ios/Podfile.lock
      
      # Created by .ignore support plugin (hsz.mobi)
      

      希望对你有帮助!

      【讨论】:

      • 应该忽略ios/Podfile.lock
      【解决方案5】:

      可能值得注意的是react-native init &lt;project-name&gt; 会为您生成一个.gitignore 文件。这可能是 React Native 当前工具和构建输出的最新版本。所以这应该是一个很好的起点。

      使用 react-native-cli 1.0.0 和 react-native 0.36.0 生成以下.gitignore 文件:

      # OSX
      #
      .DS_Store
      
      # Xcode
      #
      build/
      *.pbxuser
      !default.pbxuser
      *.mode1v3
      !default.mode1v3
      *.mode2v3
      !default.mode2v3
      *.perspectivev3
      !default.perspectivev3
      xcuserdata
      *.xccheckout
      *.moved-aside
      DerivedData
      *.hmap
      *.ipa
      *.xcuserstate
      project.xcworkspace
      
      # Android/IJ
      #
      *.iml
      .idea
      .gradle
      local.properties
      
      # node.js
      #
      node_modules/
      npm-debug.log
      
      # BUCK
      buck-out/
      \.buckd/
      android/app/libs
      android/keystores/debug.keystore
      

      【讨论】:

        【解决方案6】:

        如果您查看 React Native 示例:

        https://github.com/facebook/react-native/tree/master/Examples

        每个都有一个目录,内容类似于 react-native-cli 生成的 iOS 目录。进一步查看 Xcode 项目文件,它也在其中被引用,并查看内容 - 有诸如启动屏幕之类的东西。

        所以是的,需要 iOS 目录。

        关于 node_modules,我建议你看看这个提供更多信息的答案:

        https://stackoverflow.com/a/19416403/125680

        【讨论】:

        • 我认为 IOS 和 Android 目录不是必需的。如果你已经使用 react-native 命令行来生成你的 react-native 应用程序,你可以使用 .... react-native injection .... 来重建 IOS 和 Android 原生文件。这将使您的项目在 GitHub 存储库中更小,让其他贡献者轻松克隆您的项目并让他们使用他们的设置与 IOS Xcode 项目。
        • 我知道这是一个旧线程,但我不同意这一点。例如,一旦您更改 Info.plist 中的内容,您将在使用您的方法时遇到麻烦。也许您不会更改此文件,但大多数人会。 (想象一下使用 HTTP,而不是您必须在此文件中启用的 HTTPS)
        • 毫无疑问我们需要/ios/android 目录。 ios/build 怎么样?我们.gitignore吗?
        • 请注意,eject 命令最近已从 react-native 中删除。
        猜你喜欢
        • 1970-01-01
        • 2017-11-23
        • 2018-10-01
        • 1970-01-01
        • 2011-03-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多