While trying to pull from a remote branch I get an error:
Your local changes to the following files would be overwritten by merge: app/..../_shared.scss
Git is asking to commit the file or to stash.
The problem is - I've already done git add .
and git commit -am "trying to remove the error"
. The problem persist.
git status
says: "nothing to commit (working directory clean)"
Does anyone know how to get rid of it?
ANSWER: Move the offending file to some other location. Then delete the offending file from your tree. Pull again. then diff the changes from your offending file over the file you just pulled. hack, but it works.
Note: I found the answer here (Git asks me to commit or stash even those changes are commited), but since no one up voted it in the original thought I should repost. It's a hack, but it's the fastest route to resolution.
The “commit your changes or stash them before you can merge” error is raised when you try to pull code from a remote repository that conflicts with a local change you have made to a repository. To solve this error, either commit your change to the repository, discard your change, or stash your change for later.
Git stash vs. The key differences between the two are as follows: A commit is part of the public git history; a stash is stored locally. A commit creates a new save point on a branch; a stash reverts to a previous save point.
Git doesn't have a command that stashes only your unstaged changes. Git does, however, let you specify which files you want to stash. If you only want to stash specific changes in those files, add the --patch option. The --include-untracked option lets you stash untracked files.
If git status
reported the working directory clean, I'd bet you have an ignored file in your working directory that somebody else added to the remote repo. You could confirm that with git diff --stat your-branch remote-name/remote-branch
and git ls-files -i --exclude-standard
.
The solution would be to remove the file from the ignore file (so git status
shows it as an untracked file), stash it with the --include-untracked
option, pull the changes from your remote, and apply the stash to merge your changes back in.
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