11

I am trying something like below:

#DNX
project.lock.json

and

*.lock.json

but it does not seem to be ignoring these files.

tavier
  • 1,744
  • 4
  • 24
  • 53
  • 1
    Is the file `project.lock.json` already tracked by `git`? – axiac Apr 21 '16 at 08:07
  • It shows up (in the list of pending changes) all the time whenever I change anything in my project and compile it. I do not want to commit them so wanted to add them to gitignore file. – tavier Apr 21 '16 at 08:08
  • 2
    Possible duplicate of [Making git "forget" about a file that was tracked but is now in .gitignore](http://stackoverflow.com/questions/1274057/making-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – axiac Apr 21 '16 at 08:13
  • Is this the only file that is not ignored by git or is a general issue? – koninos Apr 21 '16 at 08:19

2 Answers2

20

If file is already tracked to git, then you must first remove it(physically file must be placed out of git folder for the time), commit changes and add the file again to folder. Then git will begin ignoring it using your instruction.

Factory Girl
  • 910
  • 4
  • 18
  • 29
  • 12
    Or you can leave the file where it is but remove it from the index using `git rm --cached project.lock.json`. The solution suggested by this answer works too but you still have to run either `git rm project.lock.json` or `git add project.lock.json` before committing (to put the deletion into the list of changes to be committed). – axiac Apr 21 '16 at 08:13
  • 4
    If you have several projects, use `git rm -r --cached *.lock.json` in your root (solution) directory to remove project.lock.json file in all subfolders from the index. – Andriy Tolstoy Sep 07 '16 at 09:18
1

from https://learn.microsoft.com/en-us/nuget/schema/project-json :

The project.lock.json file is generated in the process of restoring the NuGet packages in projects that use project.json. It holds a snapshot of all the information that is generated as NuGet walks the graph of packages and includes the version, contents, and dependencies of all the packages in your project. The build system uses this to choose packages from a global location that are relevant when building the project instead of depending on a local packages folder in the project itself. This results in faster build performance because it's necessary to read only project.lock.json instead of many separate .nuspec files.

The project.lock.json is automatically generated on package restore, so it can be omitted from source control by adding it to .gitignore and .tfignore files. However, if you include it in source control, the change history will show changes in dependencies resolved over time.

AlexGH
  • 2,735
  • 5
  • 43
  • 76