What is a .lock file?
Dependency Lockfile / Lock Marker · Code and data
A .lock file is usually a dependency lockfile (yarn.lock, Cargo.lock, Gemfile.lock, composer.lock) that pins exact package versions, or a temporary marker a program creates to signal a resource is in use.
What is a .lock file used for?
Package managers write lockfiles so every install resolves to exactly the same dependency tree: the manifest says what you want, the lockfile records what you got, down to versions and checksums. They are generated files, edited by tools, not by hand.
The second meaning is a lock marker: an often-empty file (for example on a database or a running app's profile directory) that prevents two processes using the same resource. Those can be deleted safely only when the owning program is not running.
How to open a .lock file
The .lock format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list. For a step-by-step walkthrough, see how to open a .lock file.
Windows
- any text editor (to inspect)
macOS
- any text editor (to inspect)
Linux
- any text editor (to inspect)
.lock file signature (magic bytes)
Programs recognise a .lock file by the bytes at the start of the file, not by its name. These are the signatures for Lockfile.
| Hex signature | Offset | Note |
|---|---|---|
| (no fixed signature) | 0 | plain text; no fixed magic bytes |
See the full magic-numbers reference for every format.
Frequently asked questions
What is a .lock file?
A .lock file is usually a dependency lockfile (yarn.lock, Cargo.lock, Gemfile.lock, composer.lock) that pins exact package versions, or a temporary marker a program creates to signal a resource is in use.
Should I commit lockfiles to git?
For applications, yes: yarn.lock, Cargo.lock and friends guarantee identical installs for the whole team and CI. Libraries sometimes leave them out; follow your ecosystem's convention.
Can I delete a .lock file?
A dependency lockfile: only if you intend to re-resolve all versions on the next install. A lock marker: only when the program that created it is not running, otherwise it is protecting something.
Why does my install fail with a lockfile conflict?
The manifest and the lockfile disagree, often after a merge. Re-run the package manager's install/update so it reconciles and rewrites the lockfile, then commit the result.
Related formats
Sources
Details on this page were checked against authoritative references: