Particularly the .DS_Store file, I'm on a mac so I of course put this in my .gitignore. I don't care about the file at all. But for some reason it is trying to pull it from the bare repo I setup as a server.
Updating 8e11f79..b315527
error: Your local changes to the following files would be overwritten by merge:
.DS_Store
config/wi-fi.txt
web/.DS_Store
Please, commit your changes or stash them before you can merge.
Aborting
The Git “Your local changes to the following files would be overwritten by checkout” error occurs when you make changes on two branches without committing or stashing those changes and try to navigate between the branches. You can fix this issue by either stashing your changes for later or adding them to a commit.
If you have committed changes to a file (i.e. you have run both git add and git commit ), and want to undo those changes, then you can use git reset HEAD~ to undo your commit.
Not a silver bullet, but the following worked for me:
git restore --staged ../.DS_Store
Since you got the error due to a pull, the damage has already been done: Someone has already committed a .DS_Store
file to git
. This should never happen, of course, but it has happened.
You really don't want such files to be under version control, because
git
will modify them when it checks out a commit, or, even worse, it will actively merge changes from someone else into a local .DS_Store
when you merge a branch possibly creating a broken .DS_Store
file. I have no idea what your OS does with the contents of these files, but it's not expecting you to change them in any way.
You will get an error whenever you try to checkout a revision containing a .DS_Store
file when your OS has modified it.
Non-Apple users won't like the .DS_Store
files littering your repository.
I would advise you to try to hunt down the origin of the file, because that information is central for how you can fix the issue. The command
git log --all -- .DS_Store
gives you a list of all the commits that have touched the .DS_Store
file. These are the commits that you need to rewrite to remove the .DS_Store
from your history.
Rewriting the commits can, of course, be done with the big gun git filter-branch
, but as long as it's only recent commits that have not been merged yet, you can get away with doing a git rebase -i
.
And, of course, when you are done, put .DS_Store
in your .gitignore
and check it in. This should stop people from (accidentally) adding .DS_Store
files in the future.
Just remove .DS_Store :)
Worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With