12

The setup

New intellij install, new sourcetree installation, new android project, .gitignore has been initialized as:

*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures

The problem

The files in the gradle wrapper, that's gradle/wrapper/gradle.properties and gradle/wrapper/gradle.jar are ignored. And they should be added.

$git add gradle/wrapper/gradle-wrapper.jar 
The following paths are ignored by one of your .gitignore files:
gradle/wrapper/gradle-wrapper.jar

It does not tell me which .gitignore file.

There is no .gitignore in gradle/ or gradle/wrapper.

While I can force this, I don't want to forget in future projects.

Software Engineer
  • 15,457
  • 7
  • 74
  • 102
weston
  • 54,145
  • 21
  • 145
  • 203

1 Answers1

13

It sounds like a global ignore file is what’s gumming up the works here. You can use git check-ignore --verbose gradle/wrapper/gradle-wrapper.jar to see exactly what pattern from which file is determining git’s ignore behavior. (Docs on git check-ignore)

I think the best real solution here to make sure that this particular file is not ignored, irregardless of global ignore files or broad rules for ignoring .jar files.

To that end, you can add !/gradle/wrapper/gradle-wrapper.jar to the end of your repo’s .gitignore file. (See the finer points of .gitignore file pattern matching & exclusion at bottom of the docs on .gitignore)

roosto
  • 843
  • 8
  • 9
  • The excluding line was just `gradle`. I found I could only re-include the files if I added `!gradle` Would you expect that? – weston May 27 '18 at 12:59
  • @weston `!gradle` at some point in the file, should re-include any file named `gradle` that was previously excluded by a previous rule in the file. However, in this case, an “ignore” pattern followed by the same explicit “do not ignore” pattern does not make much sense to me. Presumably a broad “ignore” pattern is there for a reason, and anything that is an exception that to that broad pattern should be expressed with a more narrow pattern. E.g., with my answer’s example: ignore `*.jar` generally, but explicitly do _not_ ignore this `.jar`, at this path, in this project. – roosto May 31 '18 at 18:20
  • Yeah I agree, but couldn't get `!/gradle/wrapper/gradle-wrapper.jar` in the project's local `.gitignore` to work, only `!gradle`. – weston May 31 '18 at 18:29
  • Weird. I’ve never gotten quite clear on whether or not you have to commit changes to a `.gitignore` repo before its new rules will be honored, or if it being modified and/or staged is enough. Maybe your trouble had something to do with that? – roosto May 31 '18 at 18:32
  • 1
    Well it respects `!gradle` immediately. It is weird, I will investigate further sometime. – weston May 31 '18 at 18:34