Can't switch git branches because of fileHashes

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:
Please commit your changes or stash them before you switch branches.

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?

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
1 Like

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