简体   繁体   中英

.DS_Store Causing Git Issues

I recently made a new branch, committed to it, and switched back to an old branch.

I tried to check out the new branch, but I got this error:

error: The following untracked working tree files would be overwritten by checkout:
client/.DS_Store

So, I did some googling, and learned that these should have been in my .gitignore. So I added them to my global .gitignore to prevent having this problem in the future. But that doesn't fix my problem in the present, which is that when I use this command to fix the error as I've seen suggested, it doesn't work, throwing the following error:

git rm --cached client/.DS_Store
fatal: pathspec 'client/.DS_Store' did not match any files

I really need to switch back to my other branch! How do I do that at this point?

EDIT: My new global .gitignore:

# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases #
######################
*.log
*.sql
*.sqlite

# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

Your gitignore for that folder seems to be incorrect.

Try this

# OS generated files #
######################
client/.DS_Store
## This one might be better
# **/.DS_Store

I believe that should work.

Or you can try

git add . && git stash

That should get you to the other branch, but you'll probably want to fix up your .gitignore.

Generally when you are stuck with files that stop you from changing branches you can temporarily stash them and then pop them out again, stash is like a little dodgy branch you can use for emergencies, just don't forget not to pop them out of you could bring on more confusion to your git workflow.

Stash only stashes added files so this is what I do.

  1. git status (check to see if any files are untracked)

  2. git add . (Only if untracked files exist)

  3. git stash (hides the files away in the stash branch

  4. Now you have a "clean" repo you can change branch and do what you want

You probably want to go to your second branch and then git merge branchwithgitignore

One your done u can do:

git stash pop

and everything should just work itself out here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM