Aman Verma
Aman Verma

Reputation: 3325

How to gitignore a particular Java file or any folder or any XML file in Android project?

I have a project in Bitbucket and I want to give access to one of my intern. I want to ignore certain Java files and certain file inside debug folder.

I have tried using the way, adding this line in my gitignore file:

/app/src/main/java/com/example/amanv/emulatordetection/NewActivity.class

However, this didn't work out.

I also tried:

/NewActivity.class

didn't work out too.

How can I do that?

Upvotes: 4

Views: 6701

Answers (3)

Saharsh Pandey
Saharsh Pandey

Reputation: 160

You can not ignore those files that you have previously committed, for that you have to remove those files from your git.

  1. To do that first go to your file directory.

  2. Now type this command to remove the file from your git.

    git rm --cached [filename]

  3. Now the file has been removed from your branch, and now you have to add the file name in your .gitignore file.

    filename.java (Remember that the activity extension should be in java.)

  4. After that, add the files to the branch and then commit them. Then finally, push and you will see the files are ignored.

    Check how i did...

Upvotes: 7

Wizzard
Wizzard

Reputation: 76

Please mind, that the path of files you want to ignore with a .gitignore file are relative to the path of your .gitignore file in your repo.

so:

/NewActivity.class

means: ignore the file NewActivity.class in the same directory as .gitignore and not in subdirectories

NewActivity.class

means: ignore the file NewActivity.class in the same directory as .gitignore and in all subdirectories

If you want to use: /app/src/main/java/com/example/amanv/emulatordetection/NewActivity.class then your .gitignore file has to be located in a parent direcory of app, which has to be part of your repository of course.

Upvotes: 3

Vivek Mishra
Vivek Mishra

Reputation: 5705

I think the extension should be .java instead of .class.

So instead of this

/app/src/main/java/com/example/amanv/emulatordetection/NewActivity.class

It should be this

/app/src/main/java/com/example/amanv/emulatordetection/NewActivity.java

Upvotes: 1

Related Questions