Reputation: 3311
I have 2 branches in my Java project: master and refactor. I've finished working on refactor so now would like to checkout master
and merge refactor into master. While working on the refactor, I also added some files to .gitignore (one of them was .idea) and now I get:
[michal@michal-pc MCleaner]$ git checkout master
error: The following untracked working tree files would be overwritten by checkout:
.idea/description.html
.idea/misc.xml
.idea/modules.xml
.idea/project-template.xml
.idea/vcs.xml
Please move or remove them before you switch branches.
Aborting
I've read many posts and nothing works. How can I remove those files without accessing master branch? Is there a way to fix that? Please provide cmd commands if you can, I'm still new to git.
Here is the output from git status
:
On branch refactor
Your branch is up-to-date with 'origin/refactor'.
Untracked files: (use "git add <file>..." to include in what will be committed)
.idea/
target/
nothing added to commit but untracked files present (use "git add" to track)
Upvotes: 10
Views: 18833
Reputation: 3090
First run
git checkout <branch_name>
The result will be something like the following
error: The following untracked working tree files would be overwritten by checkout:
.idea/codeStyles/Project.xml
.idea/codeStyles/codeStyleConfig.xml
.idea/workspace.xml
Please move or remove them before you switch branches.
Aborting
If you're ok to lose any data in those files (THEY WILL BE OVERWRITTEN) go ahead and run
git checkout <branch_name> --force
Upvotes: 12
Reputation: 11
Add these files which you do not wish to track in the .gitignore
file.
As a best practice, you should only be tracking your source code and resources files specific for your project. IDE project specific settings files should not be tracked and committed. By doing this, the project becomes IDE agnostic and any developer will be able to checkout the repo and work seamlessly irrespective of any IDE he chooses.
Example: Add these in the .gitignore
file
.idea #intellij files
.settings #eclipse files
Note: Similarly add other IDE settings directories like this.
Then commit the changes.
If the files are currently in the remote repo, then delete those files before you commit the changes.
Upvotes: 1
Reputation: 1
Add the following to .gitignore
.idea
and remove this directory
git rm -r .idea
Then commit changes.
Upvotes: 7