Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot Pull b/c "You have unstaged changes", but status says there are no changes

Tags:

git

I'm working with a developer here who is seeing a weird issue that I've never encountered before. He's working on a repository and needs to pull the latest changes from someone else before he can push. All of his changes are committed.

$ git pull
Cannot pull with rebase: You have unstaged changes.
Please commit or stash them.

Which seems reasonable enough until...

$ git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 3 and 1 different commit each, respectively.
#
nothing to commit (working directory clean)

Say what?

I've tried git reset --hard HEAD before pulling, but the pull still fails.

Only one guy is seeing this and he's on a Mac (OSX 10.6.8). Any ideas? I'm about to pull my hair out.

like image 692
Rob Wilkerson Avatar asked Dec 03 '12 21:12

Rob Wilkerson


People also ask

How do I fix unstaged changes in git?

For all unstaged files in current working directory use: git restore . That together with git switch replaces the overloaded git checkout (see here), and thus removes the argument disambiguation. If a file has both staged and unstaged changes, only the unstaged changes shown in git diff are reverted.

Can you git pull with unstaged changes?

Cannot pull with rebase: You have unstaged changes. Please commit or stash them. Git stash command is kind of commit stored changes to temporary space and clean working copy. Then your working copy will be reverted to HEAD.It is a good place to store uncommitted changes.

Can I rebase with unstaged changes?

You'll often want to do two things: change the commit message, or change the actual content of the commit by adding, removing and modifying files. error: cannot rebase: You have unstaged changes.

How do you commit unstaged changes?

To unstage commits on Git, use the “git reset” command with the “–soft” option and specify the commit hash. Alternatively, if you want to unstage your last commit, you can the “HEAD” notation in order to revert it easily. Using the “–soft” argument, changes are kept in your working directory and index.


3 Answers

Instead of

git pull

try

git fetch
git rebase -p origin/master

If that doesn't work you can try

git pull --no-rebase

How to check why this message occurs

Make sure you on a branch, not a detached head. Rebasing doesn't work on a detached head.

Run the following commands, the result should be no output.

git update-index -q --ignore-submodules --refresh
git diff-files --ignore-submodules
git diff-index --cached --ignore-submodules HEAD --
like image 71
Peter van der Does Avatar answered Oct 22 '22 16:10

Peter van der Does


Are you working on local filesystem or nfs share?

I had exactly the same problem when I was working on nfs share.

I have added noatime option to the mount command and it helped:

mount -t nfs -o noatime,... device dir
like image 44
Tomasz Avatar answered Oct 22 '22 16:10

Tomasz


for me issue was with files in secure folder

  1. only this command has shown that there are files unstaged

    git diff-files --ignore-submodules
    
  2. de-configure git-crypt and re-encrypt files in work tree

    git-crypt lock
    
like image 1
srghma Avatar answered Oct 22 '22 17:10

srghma