Safeguard
Developer Tools•

Which lockfile do I commit for each ecosystem?

A table of the file that pins exact dependency versions for npm, Cargo, Python, Go and Maven, and whether to commit it, drawn from each tool's own docs.

Safeguard Security Team
4 min read

Commit the file your ecosystem uses to record exact dependency versions: package-lock.json for npm, Cargo.lock for Rust, and the pinned requirements file for Python. Go uses go.sum for hashes. Maven has no default lockfile and relies on declared versions. Check your team's convention for the details.

The lookup table

EcosystemFileWhat the docs say
npmpackage-lock.jsonIntended to be committed to source repositories so teammates, deployments and CI install the same dependencies
RustCargo.lockHolds exact dependency information, maintained by Cargo, and "when in doubt, check Cargo.lock into version control"
Python (pip)A requirements filepip freeze outputs installed packages in requirements format, which you can review and pin
Gogo.sumThe go command checks downloaded module hashes against go.sum, and fetches from the checksum database if a hash is missing
MavenNone by defaultYou can guarantee a version by declaring it explicitly in your POM

Why the lockfile belongs in git

A manifest says what you are willing to accept. A lockfile says what you actually got. Without the second file, two developers building a day apart can get different code, and a bad release published in between reaches you without a review.

The Cargo Book states the reasoning plainly: if you build today and send a copy to someone who builds tomorrow, new upstream commits could change the result, and reproducible builds are the goal. The lock records exact revisions so the same inputs produce the same build.

Python and Maven need a decision

Python has several workflows, and pip itself is described in its docs as not a workflow management tool, so your team has to choose how to pin. Many teams commit a fully pinned requirements file, sometimes with hashes. See pip require-hashes mode.

For Maven, the dependency mechanism picks the version of the nearest definition in the dependency tree. That can surprise you, so teams often declare versions in dependency management or a bill of materials. See how Maven picks a version.

New-hire checklist

  1. Identify your repo's ecosystem and its pinning file.
  2. Confirm that file is tracked in git and not in ignore rules.
  3. Commit lock changes in the same pull request as manifest changes.
  4. Use the frozen or locked install in CI.
  5. Review lockfile diffs, not just manifest diffs.

Where Safeguard fits

Safeguard can do the inventory and watching for you. Its SBOM and dependency scanning lists what a repository actually pulls in, reachability analysis helps separate reachable findings from noise, and policies can gate a pull request. You can try a free scan on a repository to see the output.

Try it yourself

Click through it at your own pace, or open it full screen. See how exact resolved versions, not just ranges, show up in the inventory.

Quick check

Should a library commit its lockfile?

Practice differs by ecosystem and project type. Follow the docs for your tool and your team's convention.

Can I edit a lockfile by hand?

Avoid it. The Cargo Book says Cargo.lock should not be edited manually, and the same caution applies to other generated lock files.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.