Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git asks me to commit or stash changes on checkout master, even though all changes were committed?

Tags:

git

I have two branches locally, master and Berislav. The latter is currently active, and I have committed all the changes. When I try to checkout to master, I get the following message:

error: Your local changes to the following files would be overwritten by checkout: [list of files changed in the active branch] Please, commit your changes or stash them before you can switch branches. Aborting

However, everything else I tried -- commit, status, merge -- tells me that there's nothing to commit (working directory clean). What do I need to do to get to my master branch?

EDIT: When I try git stash, I'm getting:

error: feeding unmodified [file path] to diffcore

for all the files listed in the error above.

like image 477
Berislav Lopac Avatar asked Jan 03 '12 07:01

Berislav Lopac


People also ask

How do you solve please commit your changes or stash them before you merge?

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 commit or stash?

A commit creates a new save point on a branch; a stash reverts to a previous save point. A new commit leaves files in the working tree unchanged; a stash resets files in the working tree to the previous commit point. A commit is a public record of file changes; a stash is local.

How do you stash all staged changes?

Stage all your files that you need to stash. Run git stash --keep-index . This command will create a stash with ALL of your changes (staged and unstaged), but will leave the staged changes in your working directory (still in state staged). Now your "good stash" has ONLY staged files.


2 Answers

I encountered a similar problem today. git status wasn't listing the files which checkout was complaining about. I did a:

git checkout -- path/to/file 

And that undoes any changes to the file.

An even easier way to undo all unstaged changes on current working directory [1]:

git checkout -- . 

[1] - Be warned - you will lose any other unstaged changes you were working on (if any). If you don't know what you are doing, then keep a backup of the files you were working on :)

like image 105
Munawwar Avatar answered Oct 14 '22 09:10

Munawwar


As simple as this:

git stash git stash pop 

The "errors" you see when running git stash aren't anything to be concerned about. It's just git recognizing that the file doesn't have any uncommitted changes.

like image 34
user697576 Avatar answered Oct 14 '22 07:10

user697576