You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native项目中如何正确配置.gitignore忽略AndroidManifest.xml文件

解决React Native中.gitignore忽略已提交文件的问题

Hey there! I've run into this exact issue before with React Native projects, so let me walk you through how to fix it properly.

The core problem here is that Git already has your AndroidManifest.xml in its tracking history (since you pushed it once already). Adding a file to .gitignore only works for files Git hasn't started tracking yet—once a file's been committed, .gitignore won't ignore it automatically.

Here's what you need to do step by step:

  • First, double-check your .gitignore entry to ensure the path is correct relative to your project root. It should be exactly:

    android/app/src/main/AndroidManifest.xml
    

    Note: If you're on Linux or macOS, watch out for case sensitivity—make sure the path matches the actual file's casing perfectly.

  • Next, tell Git to stop tracking the file without deleting your local copy (this is crucial, you don't want to lose your API key!). Run this command in your project root:

    git rm --cached android/app/src/main/AndroidManifest.xml
    

    The --cached flag removes the file from Git's tracking index but leaves your local file completely intact.

  • Commit this change to your repository to formalize the tracking removal:

    git commit -m "Stop tracking AndroidManifest.xml to protect Google API key"
    
  • Finally, push this commit to your remote repository. From now on, any changes you make to the local AndroidManifest.xml won't show up in Git status, and it won't be pushed to the remote again.

Quick Notes for Team Environments

If you're collaborating with others:

  • When teammates pull this commit, their local AndroidManifest.xml won't be deleted, but Git will stop tracking it for them too. They should ensure their .gitignore has the same path entry.
  • If your remote repository already has the sensitive API key in its commit history, you might want to rewrite the history to remove it. This uses tools like git filter-repo—just make sure to back up your repo first, as history rewrites can be risky if not done carefully.

内容的提问来源于stack exchange,提问作者Luís Fernando

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:45:15