35

Occasionally, when I do the following...

git reset --hard
HEAD is now at 0123abde comment is here
git pull
Updating 0123abde..456789fa

I get the error...

error: Entry 'filename' not uptodate. Cannot merge.

The only workaround I have found is to 'git reset --hard', delete the offending file(s) then do 'git pull'. That doesn't seem right to me. Shouldn't a hard reset remove any and all local changes thus allowing me to pull the latest without any merge issues? Am I using git wrong? :)

This is on a CI machine so any changes here are unwanted. I'm using git version 1.6.1.9.g97c34 on Windows Vista.

James Bobowski
  • 475
  • 1
  • 4
  • 7

7 Answers7

56

The easiest solution I have found to this problem is:

git add .
git merge --abort
Christophe Moine
  • 816
  • 1
  • 7
  • 7
23

I was having the same issue and I renamed the file which was causing this and did a git pull. It pulled that missing file and fixed the issue.

vsingh
  • 291
  • 3
  • 4
15

This also might happen due to using --skip-worktree or --assume-unchanged commands and git prevent you to do: checkout, merge, rebase or pull.

The skipped files/directory might not work if we're doing the following approach:

  • git stash
  • git merge --abort, &
  • git rm --cached this also doesn't work for the skipped file this command will throw: fatal: pathspec [file] did not match any files instead

Check for the solution for skipped files here

$: git update-index --really-refresh
<file>: needs update

Optional if you want to remove the skipped or untracked dir/files on your local

$: git reset --hard

If none of the above commands fix the issue, you just have to undo the file from skipped tree, e.g:

$: git update-index --no-skip-worktree [file]

If you skipped the directory, just go here for detail how to skip/undo recursively, e.g:

find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && pwd && git ls-files -z ${pwd} | xargs -0 git update-index --skip-worktree" \;
mochadwi
  • 1,190
  • 9
  • 32
  • 87
  • THANK YOU! `git update-index --no-skip-worktree [file]` solved my problem when nothing else seemed to work. My eternal gratitude. – Gifford N. Jul 16 '23 at 11:22
14

The general idea behind "Entry 'filename' not uptodate. Cannot merge." is:

You have changes to files in your working directory that will be overwritten, removed or otherwise lost if the checkout and change to the new branch were to proceed.

It has been reported that this message could be "spurious" at time, (potentially because "git pull" did not refresh the index before trying to merge) but the fix was in Git1.6.1.
However, it may still be in mSysGit 1.6.1, so do you see the same error with a more recent mSysGit version ? (like 1.6.3)


Before Git 2.30.1 (Q1 2021), "git stash"(man) did not work well in a sparsely checked out working tree.

See commit ba359fd, commit b34ab4a, commit a31e48d (01 Dec 2020) by Elijah Newren (newren).
(Merged by Junio C Hamano -- gitster -- in commit 62fb47a, 15 Jan 2021)

t7012: add a testcase demonstrating stash apply bugs in sparse checkouts

Signed-off-by: Elijah Newren

Applying stashes in sparse-checkouts, particularly when the patterns used to define the sparseness have changed between when the stash was created and when it is applied, has a number of bugs.

The primary problem is that stashes are sometimes only partially applied.

In most such cases, it does so silently without any warning or error being displayed and with 0 exit status.

There are, however, a few cases when non-translated error messages are shown and the stash application aborts early.

The first is when there are files present despite the SKIP_WORKTREE bit being set, in which case the error message shown is:

error: Entry 'PATHNAME' not uptodate. Cannot merge.

The other situation is when a stash contains new files to add to the working tree; in this case, the code aborts early but still has the stash partially applied, and shows the following error message:

error: NEWFILE: does not exist and --remove not passed
fatal: Unable to process path NEWFILE
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I'll update to the latest mSysGit. Thanks for the quick and compendious response! – James Bobowski May 19 '09 at 02:03
  • Just wanted to add that after I updated mSysGit to a newer version, this specific problem never occurred again. So indeed, that was the root cause of my issue. – James Bobowski Feb 03 '10 at 04:01
  • I wanted these files to remain in Untracked Files list, hence I was able to get out of this situation with `git rm --cached`. Full comment here: https://stackoverflow.com/questions/1248029/git-pull-error-entry-foo-not-uptodate-cannot-merge#comment100131900_1248029 – Deep Jun 27 '19 at 10:19
4

I had this same issue when I was trying to run

git merge --abort

To get it to work, I staged the changes I didn't want. Once I did that, git was able to successfully undo them.

Forklift
  • 949
  • 8
  • 20
  • I've also had this happen spuriously in response to `git merge --abort`, complaining about an unchanged file. In my case, `git status` caused git to fix itself and I was able to `git merge --abort` successfully afterward. – Theodore Murdock Jan 30 '23 at 21:37
3

This error may occur after removing a file from an index with assume-unchanged and then trying to check out another branch. For instance,

git checkout master

and even

git checkout -f master

Results an error:

error: Entry 'gradle/apk.gradle' not uptodate. Cannot merge.

The solution is to return file back to index with:

git update-index --no-assume-unchanged gradle/apk.gradle

Then you may finally proceed with a normal checkout.

Leo DroidCoder
  • 14,527
  • 4
  • 62
  • 54
0

I had the same issue when I tried to git merge --abort in a sparsely checked out git repo, none of the solutions worked for me. Instead I did (assuming I am on branch my_branch)

git checkout -b BAD_BRANCH  # Switch to another branch
git add -u                  # Stage all the mess
git commit -m "BAD COMMIT"  # Commit all the mess
git checkout my_branch      # Go back to my branch
git branch -D BAD_BRANCH    # Delete branch with all the mess
Dave Reikher
  • 1,645
  • 1
  • 16
  • 15