13

I've got a strange issue here with one of my git repositories. I cannot add certain files. Git states:

$ git add Konstruktion/Druckteile/1x_*
warning: CRLF will be replaced by LF in Konstruktion/Druckteile/1x_Hals.gcode.
The file will have its original line endings in your working directory.
error: unable to create temporary file: No such file or directory
error: Konstruktion/Druckteile/1x_Nickhalter_links.STL: failed to insert into database
error: unable to index file Konstruktion/Druckteile/1x_Nickhalter_links.STL
fatal: adding files failed

But only for this single file. All other files in the same directory, even with similar names (e.g. 1x_Nickhalter_rechts.STL) work like a charm. Why only this file? What's special about it?

What can I do to figure out what's wrong?

Ah, just for info: it's git 1.8.5.2.msysgit.0 running on Windows 8.1 (64bit).

Thanks a lot.

Cheers, Hendrik

Hendrik Wiese
  • 2,010
  • 3
  • 22
  • 49

5 Answers5

14

I had the exact same problem when adding files. The following did the trick for me:

git config --global core.fscache false

Don't know exactly why it works but hopefully it can work for others.

tocar
  • 141
  • 1
  • 4
  • Probably an issue with the Windows file system cache getting corrupted. In my case, I was able to get my directory into working shape by executing this command. Then afterwards, I turned fscache back on and everything continues to work. – jomofrodo Mar 26 '18 at 17:46
  • This worked for me. Set to false, add files, then set to true again. – Tom Apr 05 '19 at 07:44
  • This worked for me also, the files are created after setting core.fscache to false. Thank you. – Kamal SABBAR Nov 26 '20 at 11:26
  • If you don't want to disable caching, just `git rm --cached ` the offending files. – Chiramisu Jan 28 '22 at 20:47
8

This worked for me:

export TMPDIR="/tmp/"

Yep, seriously. No idea what this actually did, but it worked, so I'm not exactly complaining. This might be a fix that only worked for me, because I can't reproduce the problem now that I've fixed it.

If the problem recurs when you relog, put it at the bottom of your ~/.bashrc. (or other shell config file)

SIGSTACKFAULT
  • 919
  • 1
  • 12
  • 31
  • Perfect, worked for me too. `$TMPDIR` was `/tmp` before for me. Changing it to `/tmp/` (with trailing slash) really did the trick. I didn't expect that. – miile7 Oct 25 '18 at 10:48
7

If you have "Controlled folder access" enabled in Windows 10, it might be the reason for this error.

You'd normally get a notification in the action center when such an action is blocked by Windows, similar to this:

To resolve that, press to open the start menu, and type "Controlled folder access" or part of it and launch it.
Click "Block history" and if git is there, give it access by clicking "Allow on device" (only present if not already configured - hence absent in the screenshot):

This solved the issue for me.

Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
0

Try and clone your /v/ownCloud/Bachelor Thesis (Vorlage2) into a much simpler path:

c:\Test

Then try and add that file within that simple path.

Update 2021: this is followed by git-for-windows/git issue 3110, as noted in this Git mailing list thread.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I have. New path is `/v/test/bt` which should imho be simple enough. No spaces, no umlauts, no special chars... Still the same as you can see here: http://pastebin.com/DKqjUG9Y – Hendrik Wiese Feb 10 '14 at 19:51
  • @SeveQ can you try it with a cmd shell (`git-cmd.bat`: http://stackoverflow.com/a/17084508/6309) instead of the git bash shell? – VonC Feb 10 '14 at 21:10
  • 1
    Okay, I've tried Windows Power Shell: http://pastebin.com/FXi9G4VR and Windows Command Line: http://pastebin.com/NAMb3xiK – Hendrik Wiese Feb 11 '14 at 06:36
  • @SeveQ is it possible to test it out on the main drive `C:\` instead of a network or subst drive `V:\`? And what is the value of the environment variable `TMP` and `TEMP`? Is there any special ACL associated with `1x_Nickhalter_links.STL`? (or one of its parent directories?) – VonC Feb 11 '14 at 06:49
  • `TEMP` and `TMP` are set as follows: http://pastebin.com/EKp5wMPA. `V:` is a mounted TrueCrypt container and so considered a local harddrive, no network or subst drive. I'm getting the same error on `C:` with the same folder structure. There are no different ACLs on 1x_Nickhalter_links.STL and 1x_Nickhalter_rechts.STL (the latter has been added to the repo without any issues). The files are from the same source, created in the same way. They're nearly the same size, have the same attributes. I don't see what could cause this difference in behavior of git... – Hendrik Wiese Feb 11 '14 at 07:10
  • @SeveQ as a workaround, is it possible to 1/ copy the content of `1x_Nickhalter_links.STL` into a spearate file '`test`'. 2/ `git add test`, `git commit` 3/ `git mv test 1x_Nickhalter_links.STL` (rename it to its target name)? – VonC Feb 11 '14 at 07:15
  • Doesn't work either. I have tried it with two different ways of copying: using the Explorer (CTRL+C, CTRL+V, rename) and opening the file in Sublime Text 3 and resaving it to a different file. I can't add any of the copies (test.STL and test2.STL). The error message stays the same (aside from the different filename): http://pastebin.com/ue0qEcyb – Hendrik Wiese Feb 11 '14 at 07:26
  • @SeveQ ok so the name/ACL isn't the issue. Can you start simplifying the content? Ie Trying to add the file with some line deleted at the end, and repeat the add until it works? The goal is to determine if there is a specific part of that content which causes the issue for the `git add`. – VonC Feb 11 '14 at 07:32
  • Uuuh, sure. That might take a while. It's a 221k file. Guess, fastest would be to write a script for that. I'll get back here after testing... – Hendrik Wiese Feb 11 '14 at 07:36
  • Alright. After writing a script that does that, by using it I figured that it works after just removing the last line. Now it's getting totally weird. The last line is exactly the same as in the other file that I could add without any issues. Even the line number is the same. Removing it manually has the same effect: adding works. Readding the line makes the error reappear. I've also tried to copy that line (and one or two more) from the end of the working file to the one that doesn't. The error remains. What is going on here? – Hendrik Wiese Feb 11 '14 at 08:08
  • @SeveQ either a length issue, or an encoding issue (do both files have the same encoding?). Just to check, would the error persists with a msysgit 1.8.4 instead of 1.8.5 (don't uninstall anything, just uncompress somewhere the 1.8.4 portable version: https://code.google.com/p/msysgit/downloads/list?can=1&q=portable+1.8.4&colspec=Filename+Summary+Uploaded+ReleaseDate+Size+DownloadCount – VonC Feb 11 '14 at 08:14
  • The error occurred with 1.8.4 first if I remember correctly. At least that was the version I tried adding the file for the first time. I can't test it at the moment as I am on the way to a meeting. But I'll try it later today and get back here. – Hendrik Wiese Feb 11 '14 at 08:26
  • @SeveQ Ok. The idea is that you can have as many different git version as you want on your computer, as long as you are using the portable version (and as long as global config settings like `core.autocrlf` are kept to `false`, in order to minimize any "automatic conversion" which, in your case, might corrupt the content: http://stackoverflow.com/a/21508796/6309). – VonC Feb 11 '14 at 08:36
  • Encoding is the same in both files. Size is pretty much the same either (they differ by about some hundret bytes). `core.autocrlf` is `false`. Git 1.8.4 however gives me a slightly different error message. 1.8.5 says "No such file or directory", 1.8.4 says "File exists". Anyway, the result is the same. Here's the message I get from 1.8.4: http://pastebin.com/xhcdNZPE – Hendrik Wiese Feb 11 '14 at 12:28
  • @SeveQ Strange. What does a `GIT_TRACE=1 git add test2.STL` returns? (in a cmd shell, that would be `set GIT_TRACE=1` followed by the `git add test2.STL`. – VonC Feb 11 '14 at 12:39
  • This: http://pastebin.com/g2gbK0d6 and nothing more, unfortunately... it's really strange. – Hendrik Wiese Feb 11 '14 at 12:49
  • @SeveQ Ok. The error message comes from https://github.com/git/git/blob/6a7071958620dadcce84e4faaa470407ae3d4108/sha1_file.c#L2907, coming from https://github.com/git/git/blob/6a7071958620dadcce84e4faaa470407ae3d4108/sha1_file.c#L2856-L2888. I'll have a look at that code to see what causes this error to pop up. – VonC Feb 11 '14 at 13:01
  • Alright, thanks! Sounds great. Looking forward to see what you'll find. – Hendrik Wiese Feb 11 '14 at 13:09
  • So, git 1.9.0 has just been released. Has this behavior been fixed or at least been provided with a more concrete error message? I mean, it might help in cases like this to see which temporary file could not be created and what doesn't exist (full path). Any other hopefully good news? – Hendrik Wiese Feb 15 '14 at 13:08
0

I had protected folders enabled in windows. You need to add git to apps that can modify certain folders.

07mm8
  • 2,702
  • 2
  • 8
  • 20