180

I am having the same problem as the OP on this post, but I don't understand the answer marked as correct (I don't see that it explains how to fix the situation)

I do this and get this error:

$ git update-index --assume-unchanged web.config
fatal: Unable to mark file web.config
  1. The file IS added to the repository

  2. It is NOT in .git/info/exclude

  3. It is NOT in .gitignore (it was, but I took it out, then forced web.config to be added using git add -f web.config, committed, and pushed those changes to the repo)

  4. When I do Git ls-files -o it is NOT there

So what can I do to fix?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Karen
  • 2,296
  • 3
  • 18
  • 19
  • 1
    re-read the accepted answer in the referenced question: it shall NOT appear in the output of `git ls-files -o`. If so, it's not in the repo. – eckes Nov 08 '12 at 11:32
  • my typo, it is NOT in the list, and it is most definitely in the repo – Karen Dec 13 '12 at 22:42

22 Answers22

137

I was having the same problem as you, and had followed the same four steps that you indicated above, and had the same results. This included the fact that my file was listed when executing git ls-files -o. However in my case, I also tried executing git update-index --assume-unchanged against a file that was not listed when executing ls-files -o, and I still received the same error "fatal: Unable to mark file".

I thought that perhaps it was a bug, and downloaded the latest version of git, but this did not help.

What I finally realized is that this command is case sensitive! This includes the full path and file name. After updating path to the directory so that the full path was specified with proper casing, the command executed properly.

Note that this was with Git for Windows, so you're results may vary with other platforms.

David Marchelya
  • 3,352
  • 4
  • 21
  • 24
  • 4
    Thank you SOOOO much! This worked! I think I was using all lower case before, or cd to the folder and then tried to use this command. – Karen Dec 13 '12 at 22:44
  • If the file will change then this is Wrong. The command is a promise, by the user, to Git, that it doesn't have to waste cycles on stating the file to detect if it has changed (for slow file systems;-). Eventually one of the Git commands will notice and you will be suprised. The documentation is being updated to clarify this. – Philip Oakley Dec 11 '14 at 15:52
  • 1
    Thanks, this indirectly helped me discover some bad shell script in a project. If a path does not exist, this will fail! :) – uchuugaka Jul 14 '17 at 02:37
  • 4
    Also note that this command will not work for unversioned files. If you have a file that does not exist in the repository it can be ignored in .gitignore, and boy do I feel silly typing this but I figure it might help somebody as dumb as me. :) – Jesse Ivy Jan 10 '18 at 00:36
  • Just to clarify what some of the comments have hinted at, if you're using a Windows shell that has allowed you to get away with case mismatches in your cds, you will get this error. Either give git the full path to the file (with the correct case), or cd back up and then down again (again, with the correct case at every stage). – dlf Feb 07 '19 at 21:40
64

I was having the same issue on a Mac. Case-sensitivity wasn't an issue for me - the problem was I needed to reset my git first:

Problem:

 git update-index --assume-unchanged index.php
 fatal: Unable to mark file index.php

Solution:

git reset HEAD
Unstaged changes after reset:
M   index.php
git update-index --assume-unchanged index.php
Toby Beresford
  • 1,028
  • 9
  • 18
  • 2
    I am having the same problem on Mac, and none of the suggested workarounds worked for me. Any idea? I am trying to stop tracking a directory temporarily on my machine only, the name the dir is intellij_idea_project_files/. Apparently all of the files in this directory have been properly marked except one, and that is my_project_name.iml. – Javad Feb 24 '15 at 22:14
  • 1
    had the same problem and this is the solution that worked for me, not the one about case-sensitive – CesarPim Feb 01 '17 at 23:05
  • I am also on Mac and for me the "solution" was to delete the file. (I would post this as an answer but I'm not sure what happened, maybe later.) Something weird happened. Git was saying the file was changed (I wanted to `--skip-worktree`). I got rid of local changes by running `git restore .` but skip still gave the error. Finally I tried deleting the file. Shockingly, git did not say there was a change. So clearly something funky has happened since git was definitely tracking it and I definitely deleted it and it definitely didn't say that that was a change. – Captain Man Mar 06 '20 at 20:04
  • I am on Git Bash for Windows and this helped me. I didn't even have to run the `update-index` command again after `git reset` – Chintan Mar 28 '23 at 13:30
42

In my case the tree I was marking was a directory, and not a file as in you case, and I was missing the forward slash after its name.

Incorrect -

git update-index --assume-unchanged directory-name

Correct -

git update-index --assume-unchanged directory-name/

Note the forward slash(/) in the end.

Sahil Singh
  • 3,352
  • 39
  • 62
  • 2
    Thanks, but when I do this I get "Ignoring path directory-name/" – damian Apr 11 '18 at 08:36
  • @damian Specify full file path instead of the parent directory. – Nahid May 13 '18 at 09:02
  • If I do that I get what damian does. Except my file is a file and not a folder. – Unknow0059 Oct 30 '20 at 00:26
  • 2
    Thanks, this got me past the error and then I found that I needed to add a `*` after the slash for it to ignore all the files in that folder – Curt Aug 12 '22 at 19:43
  • It seems that `update-index` doesn't work with directory paths. I wasted half a day to find a solution for this. https://stackoverflow.com/a/55860969 – Michael Ekoka Apr 15 '23 at 07:27
13

Make sure the file is added to git repo, if not add the file in git repo and then try it will work.

bisw
  • 827
  • 9
  • 13
  • the OP specifically stated that the file is in the repo – Facundo Colombier Jul 30 '23 at 16:24
  • @FacundoColombier while this answer isn't specific to the OP, I think this is an important answer at this point. This question has received a good amount of attention. So others will come to it looking for a solution to their own specific issue. For instance, this answer solved my problem. – Matthew Cole Anderson Aug 11 '23 at 20:48
7

fatal: Unable to mark file Localization/el-GR.js

What you can do is:

  1. Move to the correct path where the file is present in your local (in GITBASH)
  2. Update the index $git update-index --assume-unchanged <file name>

This helped me! :)

Mig82
  • 4,856
  • 4
  • 40
  • 63
Grace Aloysius
  • 131
  • 2
  • 2
5

If your path has spaces, you may get this error even if you have the casing right.

This results in the "fatal" error:

git update-index --assume-unchanged code/Solution Files/WebEssentials-Settings-json

To fix it, simply add quotes around the path.

git update-index --assume-unchanged "code/Solution Files/WebEssentials-Settings-json"
Jon Crowell
  • 21,695
  • 14
  • 89
  • 110
5

--assume-unchanged is about slow file systems, and a users promise that Git doesn't need to check this file, as Git can assume its unchanged. But some command still do check and produce 'surprise'!

Do not use on files which change.

Sorry to be the bringer of that news (I have a patch in process to change that documentation).

Philip Oakley
  • 13,333
  • 9
  • 48
  • 71
  • 3
    Then how is one supposed to update a file to mark it as 'do not track me' ? – WestCoastProjects Jul 26 '15 at 00:25
  • @javadba see http://stackoverflow.com/a/6964492/717355 'git rm --cached filename' – Philip Oakley Jul 26 '15 at 20:12
  • thx - upvoted on that: i had actually used it just after posting here. works. – WestCoastProjects Jul 26 '15 at 20:13
  • note that `git rm --cached filename` will delete the file when others pull – Ryan Taylor Nov 03 '16 at 17:24
  • @RyanTaylor yes, it's important for users to realise what their command is saying, which is 'stop tracking this, remove it from my revisions'. Have a read of the latest view of the maintainer, and my new patch.. https://public-inbox.org/git/20161101210448.4692-1-philipoakley@iee.org/T/#u – Philip Oakley Nov 03 '16 at 22:04
  • 1
    @javadba: for that you should use `--skip-worktree`, which is explicitly for preventing git from ever clobbering your local changes to that file, and hides it from the `git status`. Unfortunately, it can have the same issue as this OP, which is why I'm here! – Tasgall Sep 08 '17 at 00:49
5

In my case, I tried to use any of the methods above, but no luck.

After many attempts, I just thought to add my file to index through.

git add myfile.php

Git refused this action but he advised me to make it forcibly.

git add myfile.php -f

And that worked for me.

Stepanov Max
  • 159
  • 3
  • 4
4

My Problem was, that I tried the command with a * wildcard assuming it would be recursive, but it wasn't.

So what I did was

$ git reset HEAD
Unstaged changes after reset: 
M   .gradle/1.9/taskArtifacts/cache.properties.lock
M   .gradle/1.9/taskArtifacts/fileHashes.bin
M   .gradle/1.9/taskArtifacts/fileSnapshots.bin
M   .gradle/1.9/taskArtifacts/outputFileStates.bin
M   .gradle/1.9/taskArtifacts/taskArtifacts.bin

executing

$ git update-index --assume-unchanged .gradle/1.9/taskArtifacts/*

worked for me then and didn't result in OPs and my problem.

methical
  • 132
  • 1
  • 7
  • Addition: The files need to be listed exactly as they exist in ‘the index’ already. So wildcards need to be resolved by bash already and they cannot match with files not in the index. In my case for temp ignoring btw: https://stackoverflow.com/a/39583010/574370 – Spangaer Oct 05 '22 at 07:15
3

One common mistake around using this command is trying to assume either not tracked file or ignored file by git already.

Make sure first that the file is tracked by running

git ls-files | grep relative_path/to/file

If it's not showing your file, then you need to add it first:

git add relative_path/to/file

If this shows your file, or you've already added that file to git, then you should be able to run git assume commands normally:

git update-index --skip-worktree relative_path/to/file

or for folders

git update-index --skip-worktree relative_path/to/folder/

you can check if your file is assumed to be ignored by running

git ls-files -v | grep ^S

The S character represents skipped files.

Ahmed Amr
  • 579
  • 3
  • 10
3

So I had this same error when I use this:

git update-index --assume-unchanged appsettings.Development.json

So I changed it to

git update-index --assume-unchanged appsettings.development.json

I actually tried many methods at first but I ended up using this. So I guess its case sensitive

Kazeem Quadri
  • 247
  • 3
  • 5
2

Make sure you have "web.config" checked in.

If it isn't, you will get this error message.

OneSolitaryNoob
  • 5,423
  • 3
  • 25
  • 43
2

stage your file, only after that run --assume-unchanged, then unstage the file

Andrii Viazovskyi
  • 777
  • 2
  • 9
  • 15
1

I had this problem when I was trying to untrack *.orig files.

This is what I did to untrack them:

$git reset -- *.orig

if that doesn't work:

$git clean -fd
EdC
  • 1,145
  • 10
  • 8
1

Maybe useful for someone. I had the same problem and was no syntax problem, no name with spaces, no path problem, and git reset command didn't work. I was commiting from a folder inside apache www and apache service was stopped. Started again apache service and the error is gone

1

I found that sometimes this doesn't work because you've already committed the file to your .gitignore and made a push or pull. You only need to make the push and your file should be ignored on subsequent commits even when you locally modify the file.

Akah
  • 1,389
  • 14
  • 19
0

For all future visitors. None of the above resolved my issue. What I realized is the .gitignore file must be placed in the right directory. In my case, once I moved .gitignore to application's root directory the issue was resolved.

Amir
  • 197
  • 2
  • 17
0

Check if the file to be marked exists and spells correctly, especially the file path and file separator. The file separators of windows system and linux system are in different directions.

  • 1
    While not wrong, this answer doesn't really add anything to the question. All your suggestions have already been brought up in existing answers. – Matt Nov 12 '18 at 04:05
0

Had the same problem, nothing else worked (my file was tracked, and NOT in gitignore). I realised I copied the file name from terminal output a few lines above, and that made it copy the blank space AFTER the file name. Even though it looks like there is no space, I had a lot of space at the end. So copying just the file path, and keeping it in double qoutes, that helped. I also did a git reset HEAD first.

git update-index --assume-unchanged "app/src/main/java/com/username/projectName/Utils.kt"
0

In my case, i was getting the fatal: Unable to mark file error because i had pushed the file to my git repo, so git was not able to find it, first make sure you commit and push the template file that you want to keep in github but do not track it later.

Once pushed, now you can run the command git update-index --skip-worktree YOUR_FILE and modify it without this being tracked

0

For me it was because copying and pasting, the double dashes became an em dash "—assume-unchanged" instead of this "--assume-unchanged".

noobie
  • 411
  • 1
  • 12
-1

I had the same issue with cygwin in windows. Giving the full file path

Sudeep
  • 129
  • 1
  • 4