Can't switch git branches because of fileHashes


(Rob deMallac) #1

I’ve been testing using gradle on my existing maven project, using a new branch in git, and now it won’t let me switch back to the master branch. ‘git checkout master’ produces the following error:

error: Your local changes to the following files would be overwritten by checkout:
.gradle/4.0.1/fileHashes/fileHashes.bin
.gradle/4.0.1/fileHashes/fileHashes.lock
Please commit your changes or stash them before you switch branches.
Aborting

I only thought to add the .gradle directory to my gitignore file after-the-fact, which may be part of the problem.
I’m running Gradle 4.0.1 (installed via homebrew on a Mac, should that matter).

Is it safe to delete those files? Or… how best to proceed?


(Sterling Greene) #2

You shouldn’t commit anything from .gradle to version control. It sounds like master has files from .gradle already checked in, so you can’t switch between branches without those files changing.

You can try something like…

git stash
git checkout master
git rm -rf .gradle
// edit .gitignore to ignore .gradle
git add .gitignore
git commit -m 'remove .gradle'
git checkout <previous branch>
git rebase master

(Rob deMallac) #3

… and we are back to a happy codebase. Thank you, sir!