-2

I delete my unity project which has a .git folder and ask me to create an encryption key I don't know why it asks me to do that, now when I try to add files in git it refuses to add any things and it prompts this error

The file will have its original line endings in your working directory
error: open("Temp/UnityLockfile"): Permission denied
error: unable to index file 'Temp/UnityLockfile'
fatal: adding files failed

Any suggestion

suleiman
  • 29
  • 1
  • 1
  • 7
  • 1
    If the issue is related to files inside Temp directory, then Temp directory shouldn't be included in git in the first place. I'd recommend you to place this .gitignore file to your project folder and try again: https://github.com/github/gitignore/blob/master/Unity.gitignore – yasirkula Jul 26 '21 at 12:52
  • 1
    What exactly are you asking? The text with the encryption key seems to be entirely unrelated to the topic and the error message below. Can you clarify? – Joachim Sauer Jul 26 '21 at 12:57
  • Can you navigate to the Temp folder and check what UnityLockfile contains? – Lajos Arpad Jul 26 '21 at 13:59
  • The error message itself (`error: open("Temp/UnityLockfile"): Permission denied`) seems pretty clear: your computer denies permission for your Git to open that file. You could look into how your computer decides which of your own files you are allowed to read. However, as others said, it seems likely that you should not be asking Git to version-control temporary files. – torek Jul 26 '21 at 22:37
  • @yasirkula at first place i add .gitignore but i have delete my project and clone from github again – suleiman Jul 27 '21 at 20:37
  • @Joachim Sauer unrelated why ? leave encryption help me how to solve that error – suleiman Jul 27 '21 at 20:45

1 Answers1

1

In general the Temp folder is one of the things you do NOT want to be under version control! It should be ignored as mentioned by the first comment! Use this .gitignore file in the root folder of your git project!

Also see Cleaning up and Migrating existing Unity project into new one or another PC where I explained it a bit more in detail and also how to copy your project with only the necessary files.

As said if there is no such file yet simply create it, otherwise adopt the content accordingly.

Also refer to How can I make Git "forget" about a file that was tracked, but is now in .gitignore?.


In your specific case here the error itself is caused because you currently have your project opened in Unity.

In that case there is the - as the name says - LOCK file which ensures you cannot open the same project twice in a second Unity instance.

This file is locked/owned by the Unity Editor process itself and therefore can't be overwritten/accessed by git at the same time.

Now if for some reason after adding the .gitignore file mentioned above this issue still persists you can close Unity, manually delete the Temp folder, make your git merge and reopen Unity.

derHugo
  • 83,094
  • 9
  • 75
  • 115
  • Ehm .. well as said first of all use the correct `.gitignore` file .. you simply place it into your git root folder and refer to [How can I make Git "forget" about a file that was tracked, but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-can-i-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitign) – derHugo Jul 27 '21 at 21:03
  • i try to follow the step but when i push it throw me an erro ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/SuleimanAbdullah/Space-Shooter.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. – suleiman Jul 28 '21 at 13:34
  • i try to add .gitignore i get this error $ git add .gitignore fatal: pathspec '.gitignore' did not match any files git is not sexiest thing oowh – suleiman Jul 28 '21 at 13:58
  • well have you tried to close Unity, call `git pull` then add the gitignore file, then call `git rm -r --cached .` then call `git add .` (ignore the warnings about ignored files) .. then do `git commit` and only then you are ready to do `git push`. In the meantime you should tell your coworkers to not push anything new until this issue is solved – derHugo Jul 28 '21 at 14:04
  • derHugo most of you command throw me error i have tried to close unity many time i try to add gitignore i get error please correct you command – suleiman Jul 31 '21 at 17:33
  • i follow the link but i wasn't able to solve am new to git this project is very important to continue track with github and git but whenever i try add * or add . i receive this file permission denied error: open("Temp/UnityLockfile"): Permission denied error: unable to index file 'Temp/UnityLockfile' fatal: adding files failed – suleiman Jul 31 '21 at 17:51
  • can i add this project to new repo but there 1 first problem which lead to this whole issue git maximum amount to push if it is possible to create new repo help me i will do that – suleiman Jul 31 '21 at 17:54