Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git asks to commit or stash, but there's nothing to commit

Tags:

git

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.

like image 610
Kirill Avatar asked Jun 10 '12 20:06

Kirill


People also ask

How do I fix please commit your changes or stash them before merge abortion?

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.

Should I stash or commit?

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.

How do I stash changes not staged for commit?

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.


1 Answers

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.

like image 160
ellotheth Avatar answered Sep 29 '22 02:09

ellotheth