Android Studio Git .gitignore vs Project > Settings > Version Control > Ignored Files

北慕城南 提交于 2019-11-29 22:13:44
AutoM8R

Ok to answer my own question. To go back to using .gitignore, do the following:

  1. Go to Settings > Version Control > Ignored Files and remove all ignored files. Hit Apply.
  2. Still in Settings > Version Control change the type of version control from Git to none. Hit Apply.
  3. Delete the project's .git directory created previously.
  4. Create the following .gitignore file in the root directory of your project: https://stackoverflow.com/a/21049338/459095
  5. VCS > Enable Version Control... to Re-enable Git.
  6. Then right click on the project root and select Git > Add to add the entire project.

Doing the above will utilize the .gitignore file instead of Settings > Version Control > Ignored Files to commit the right files.

Tim Long

For me the process was a little easier:

  1. In Android Studio: Settings > Version Control > Ignored Files > Remove all ignored files > Apply
  2. Backup .gitignore. Create an empty new .gitignore. (in the root folder)
  3. Restart Android Studio!
  4. Fill up the new .gitignore with the old one. Don't forget to commit the change .gitignore + related ignored/deleted files!

No re-enable VCS required! I'm working with a GitRepo, which is extremely inconvient to do re-enabling VCS. The steps helped.

Using command line, this becomes easy :

> git status

On branch master

No commits yet

Untracked files: (use "git add ..." to include in what will be committed)

    .gitignore
    .idea/
    app/
    build.gradle
    gradle.properties
    gradle/
    gradlew
    gradlew.bat
    settings.gradle

nothing added to commit but untracked files present (use "git add" to track)

git add *

That's it, if you check again you'll see that your files are now added as files to checkin :

git status

On branch master

No commits yet

Changes to be committed: (use "git rm --cached ..." to unstage)

    new file:   .gitignore
    new file:   .idea/caches/build_file_checksums.ser
    new file:   .idea/codeStyles/Project.xml
    ....

Neither solution here worked for me with the latest build of android studio or rubymine and as far as I can tell this isn't supported by intellij products any more - https://youtrack.jetbrains.com/issue/IDEA-60354.

The ignore plugin seems to be the recommended solution to this problem now. See https://plugins.jetbrains.com/plugin/7495--ignore and http://ignore.hsz.mobi/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!