3

Please, I get the error "Your local changes to the following files would be overwritten by checkout" but my working tree is clean.

does anyone have any idea of what is going on here?

$ git status
On branch experiment
nothing to commit, working tree clean

$ git checkout develop
error: Your local changes to the following files would be overwritten by checkout:
app/build.gradle
Please commit your changes or stash them before you switch branches.
Aborting

(the file app/build.gradle is not in my .gitignore file)


This is the top level .gitignore file:

### Android ###

# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# Intellij
.idea
*.iml

# Keystore files
*.jks

# External native build folder generated in Android Studio 2.2 and     later
.externalNativeBuild

# Mac
.DS_Store

### Android Patch ###
gen-external-apklibs

This is a .gitignore file inside the /app directory (I don't know why it is there):

build

# Secrets
secrets.properties
Lisa Anne
  • 4,482
  • 17
  • 83
  • 157
  • 1
    Maybe you're ignoring all gradle files and not specific one? Please post the `.gitignore` content. – Maroun Sep 05 '17 at 10:04
  • What the output of `git status`? – Noufal Ibrahim Sep 05 '17 at 10:04
  • 2
    @NoufalIbrahim OP already posted it. – Maroun Sep 05 '17 at 10:05
  • My bad. This is really weird though. Are there any patterns in your `.gitignore` file that match the `build.gradle` one? Perhaps the whole directory? What do you get when you try a `git clean -n`? – Noufal Ibrahim Sep 05 '17 at 10:08
  • what is the output of `git status --untracked-files=all` ? – Pac0 Sep 05 '17 at 10:10
  • (you can also add `--ignore`to get *sure* that `app/build.gradle` is not in `.gitignore`) – Pac0 Sep 05 '17 at 10:13
  • Is `app/build.gradle` listed in the output of `git clean -nxfd`? careful with the command, although `-n` should be a dry run of the clean command it's always worth exercising caution =D – Chris Sep 05 '17 at 10:25
  • @Pac0 thank you pac, that command returns nothing – Lisa Anne Sep 05 '17 at 10:32
  • @Chris the output is Would remove .gradle/ Would remove .idea/ Would remove app/app.iml Would remove app/build/ Would remove build/ Would remove local.properties – Lisa Anne Sep 05 '17 at 10:39
  • @Chris Don’t mix `-f` and `-n` there o.O You’re lucky `-n` has a higher precedence. – poke Sep 05 '17 at 10:58
  • @LisaAnne Can you try a `git add -f app/build.gradle` and then check the status again? Does it still not appear in there? – poke Sep 05 '17 at 11:01
  • 1
    `.gitignore` isn't the only file that could be defining a relevant ignore rule. Is there anything in `.git/info/exclude`? If you run `git config --list |grep core.excludesFile` does it show anything? (If so, that config value names another file that might include ignore rules.) – Mark Adelsberger Sep 05 '17 at 12:28
  • @poke That's better advice, for some reason I picked up the bad habit of using both at some point. – Chris Sep 05 '17 at 14:17

3 Answers3

4

A wild shot :

I once read about a hidden "assume unchanged flag" (see this answer for example),
and the only way I know of for seeing if this flag is active on a file is (see this answer) :

git ls-files -v | grep '^[[:lower:]]'

What do you see when you run the above command on your repo ?

LeGEC
  • 46,477
  • 5
  • 57
  • 104
0

If anyone else wonders what's the next step after you notice that a file was added to assume unchanged with git ls-files -v | grep '^[[:lower:]]', you need to remove the flag with this command:

git update-index --no-assume-unchanged PATH/TO/THE/FILE.wtf

After that you can either git commit or git stash the changes and then you'll be able to git checkout

-2

do a git status see the files that are still to be added or changed.

This comes when there are local cahnges that can be overwritten

If you see that you dont need local changes

use git stash to flush local changes and try again