git update-index --assume-unchanged returns "fatal unable to mark file"
Asked Answered
R

23

186

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?

Riven answered 16/10, 2012 at 17:56 Comment(2)
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.Igniter
my typo, it is NOT in the list, and it is most definitely in the repoRiven
D
141

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.

Disbelieve answered 10/11, 2012 at 4:30 Comment(6)
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.Riven
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.Upbraid
Thanks, this indirectly helped me discover some bad shell script in a project. If a path does not exist, this will fail! :)Tacky
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. :)Cavender
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).Scrooge
As a complement: you also might encounter the same error facing non-unicode strings path (I got some files named something à otherthing.csv which were converted to something \303\240 otherthing.csv by git ls-files....)Twinned
W
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
Wise answered 18/9, 2014 at 10:47 Comment(4)
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.Intensify
had the same problem and this is the solution that worked for me, not the one about case-sensitiveFronde
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.Multi
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 resetKennard
S
45

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.

Supplicatory answered 11/9, 2016 at 9:12 Comment(5)
Thanks, but when I do this I get "Ignoring path directory-name/"Machmeter
@Machmeter Specify full file path instead of the parent directory.Debut
If I do that I get what damian does. Except my file is a file and not a folder.Dibasic
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 folderLiba
It seems that update-index doesn't work with directory paths. I wasted half a day to find a solution for this. stackoverflow.com/a/55860969Ra
M
13

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

Motherhood answered 13/7, 2016 at 6:35 Comment(3)
the OP specifically stated that the file is in the repoTobacco
@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.Mcclintock
By "added to git repo", you mean in the current branch, or in any branch? Currently I have the issue that a file exists in one branch, but not the other. File cannot be deleted because it's locked by server. So cannot switch branch since it thinks it would overwrite the file.Quebec
S
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! :)

Sowers answered 2/12, 2015 at 13:46 Comment(2)
$ git update-index --assume-unchanged ./.idea/vcs.xml fatal: Unable to mark file .idea/vcs.xml $ cd .idea git update-index --assume-unchanged . Worked, thanks!Shanika
AVProgrammer's solution is what worked for me on OS XBenzine
D
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"
Doublefaced answered 25/8, 2014 at 22:34 Comment(1)
In my case I had the / backwards.Ballesteros
U
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).

Upbraid answered 11/12, 2014 at 15:58 Comment(6)
Then how is one supposed to update a file to mark it as 'do not track me' ?Durston
@javadba see https://mcmap.net/q/12407/-untrack-files-from-git-temporarily 'git rm --cached filename'Upbraid
thx - upvoted on that: i had actually used it just after posting here. works.Durston
note that git rm --cached filename will delete the file when others pullCrossley
@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.. public-inbox.org/git/[email protected]/…Upbraid
@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!Abdominal
H
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.

Hilversum answered 13/7, 2019 at 11:2 Comment(0)
T
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.

Tumor answered 10/12, 2014 at 14:49 Comment(1)
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://mcmap.net/q/12408/-git-update-index-assume-unchanged-not-working-for-mePiggyback
P
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.

Pray answered 9/3, 2020 at 18:15 Comment(1)
In my case, the file was already in the list of excluded extensions.Analogy
T
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

Toluol answered 23/3, 2021 at 11:56 Comment(3)
You have two same pieces of codePelayo
The case is differentToluol
Make sense now.Pelayo
B
3

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

Beyer answered 5/7, 2022 at 12:38 Comment(0)
D
2

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

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

Decathlon answered 30/3, 2015 at 23:48 Comment(0)
T
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
Teahouse answered 19/11, 2015 at 22:42 Comment(3)
It's dangerous to ask people to execute command without telling them that this command will delete files. $git clean -fdWillful
I was stupid enough to run the command before your comment Rathore. All my files deleted!!Attis
Should remove the command that deletes files!Wesleyanism
T
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

Tamekia answered 1/6, 2017 at 16:20 Comment(0)
B
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.

Bobsled answered 18/8, 2019 at 11:50 Comment(0)
P
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.

Pyrogallate answered 19/10, 2017 at 14:55 Comment(0)
P
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.

Polychromatic answered 12/11, 2018 at 3:44 Comment(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.Sacrifice
W
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"
Workman answered 27/11, 2020 at 17:43 Comment(0)
L
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

Liquidambar answered 23/4, 2022 at 3:17 Comment(0)
P
0

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

Priestley answered 8/12, 2022 at 4:37 Comment(0)
V
0

Check that you are unignoring (--no-assume-unchanged) the file from the same path that you ran the initial ignore (--assume-unchanged) command.

I ignored the file d.txt while in path a/b/c, e.g. git update-index --assume-unchanged d.txt, but on moving to a/, I could not use git update-index --no-assume-unchanged ./b/c/d.txt, instead receiving the 'fatal: unable to mark file' message.

Vermis answered 23/2 at 5:36 Comment(0)
S
-1

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

Schoolmate answered 12/10, 2019 at 9:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.