Fixed: MLflow Doesn't Record the Git Commit of a Run Started with uv run
A run started through a project command, such as uv run log-run, gets no mlflow.source.git.commit tag, although the project is a Git repository. MLflow 3.18.0 looks for the commit next to the command's launcher in .venv, and Git ignores that folder. Reading the commit yourself and passing it to mlflow.start_run as a tag fixes it.
What I Was Doing
In Part 10 of the MLflow tutorial series, I checked which code each training run came from. The shopper project starts its runs with commands such as uv run train, and none of its runs had a commit. To see the problem on its own, I made a small package, script-demo, with one command, log-run, that logs a run:
[project.scripts]
log-run = "script_demo.log_run:main"
import mlflow
def main() -> None:
mlflow.set_tracking_uri("http://127.0.0.1:8090")
mlflow.set_experiment("script-demo")
with mlflow.start_run(run_name="from-a-script"):
mlflow.log_param("greeting", "hello")
if __name__ == "__main__":
main()
The folder is a Git repository with everything committed. I ran the command:
uv run log-run
2026/11/28 13:55:46 INFO mlflow.tracking.fluent: Experiment with name 'script-demo' does not exist. Creating a new experiment.
🏃 View run from-a-script at: http://127.0.0.1:8090/#/experiments/2/runs/c5788c992ae94711b8f9d1a59234fd86
🧪 View experiment at: http://127.0.0.1:8090/#/experiments/2
What I Expected
A mlflow.source.git.commit tag. MLflow's System Tags Reference lists it as the "Git commit hash", set "When run from git repo".
What I Got
uv run mlflow --env-file .env runs describe --run-id c5788c992ae94711b8f9d1a59234fd86
"tags": {
"mlflow.user": "you",
"mlflow.source.name": "/Users/you/source/script-demo/.venv/bin/log-run",
"mlflow.source.type": "LOCAL",
"mlflow.runName": "from-a-script"
}

No commit, and the source is .venv/bin/log-run, the launcher uv installed for the command, not the code in src.
What I Checked
Whether Git ignores the launcher's folder.
git check-ignore -v .venv
.gitignore:10:.venv .venv
Line 10 of .gitignore ignores .venv, as it should: the virtual environment doesn't belong in Git.
How MLflow 3.18.0 finds the commit. Its run context takes the source from sys.argv[0], the path of the program Python started with, and passes that path to get_git_commit in mlflow/utils/git_utils.py:
if os.path.isfile(path):
path = os.path.dirname(os.path.abspath(path))
repo = Repo(path, search_parent_directories=True)
if path in repo.ignored(path):
return None
return repo.head.commit.hexsha
The launcher's folder is .venv/bin. Git ignores it, so the function returns None and MLflow sets no tag.
Whether a script inside the repository gets the tag. Python can start the same code from its file in src with -m:
uv run python -m script_demo.log_run
Described with mlflow runs describe, the run that command logged had the commit, with the source in src:
"mlflow.source.name": "/Users/you/source/script-demo/src/script_demo/log_run.py",
"mlflow.source.type": "LOCAL",
"mlflow.source.git.commit": "7c227654e4eaae4d8ea45e8d602ba68e1fe4d05b",
"mlflow.source.git.branch": "main",
Why It Happens
MLflow looks for the commit next to the file the program started from. A command installed by a package starts from a launcher in .venv/bin, and Git ignores .venv, so MLflow concludes the code isn't in Git.
The Fix
Read the commit yourself and pass it to mlflow.start_run as the same tag. start_run's tags parameter is "An optional dictionary of string keys and values to set as tags on the run":
import subprocess
from pathlib import Path
import mlflow
def git_commit_tag() -> dict[str, str]:
"""MLflow's commit tag for this code, or no tag outside a Git repository."""
try:
result = subprocess.run(
["git", "rev-parse", "HEAD"],
cwd=Path(__file__).parent,
capture_output=True,
text=True,
check=True,
)
except OSError, subprocess.CalledProcessError:
return {}
return {"mlflow.source.git.commit": result.stdout.strip()}
def main() -> None:
mlflow.set_tracking_uri("http://127.0.0.1:8090")
mlflow.set_experiment("script-demo")
with mlflow.start_run(run_name="from-a-script", tags=git_commit_tag()):
mlflow.log_param("greeting", "hello")
if __name__ == "__main__":
main()

git rev-parse HEAD runs in the file's folder, inside the repository, so it finds the commit wherever the command starts. Outside Git, the function returns no tag and the run goes ahead.
After the Fix
I committed the change and ran the same command:
uv run log-run
🏃 View run from-a-script at: http://127.0.0.1:8090/#/experiments/2/runs/40e85fa4cd5d40a8aa023ae232be40aa
🧪 View experiment at: http://127.0.0.1:8090/#/experiments/2
uv run mlflow --env-file .env runs describe --run-id 40e85fa4cd5d40a8aa023ae232be40aa
"mlflow.source.name": "/Users/you/source/script-demo/.venv/bin/log-run",
"mlflow.source.type": "LOCAL",
"mlflow.source.git.commit": "1354555e48dea8aaa128baf57eb6bd24d02d7405",
git rev-parse HEAD
1354555e48dea8aaa128baf57eb6bd24d02d7405

The run started through the command now records the repository's commit.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Removing .venv from .gitignore so MLflow finds the commit | Git starts tracking the virtual environment | Keep .venv ignored and pass the tag |
| Training before committing | The tag names the previous commit | Commit, then run |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
mlflow.source.name ends in .venv/bin/<command> and there's no commit | The run started through a package's command | Pass the tag, or start the file with python -m |
FAQ
Can I fix it without changing the code?
Yes, by starting the module with uv run python -m script_demo.log_run: MLflow then sees the file in src and records the commit and the branch itself. You lose the short command, so the tag is the better fix for a project's commands.
Does the branch tag matter?
MLflow sets mlflow.source.git.branch when it finds the commit itself, as the -m run shows. The commit alone identifies the code exactly.
Conclusion
MLflow 3.18.0 skips the commit for runs started through a package's command, because it looks next to the launcher in the Git-ignored .venv. Reading the commit with git rev-parse HEAD and passing {"mlflow.source.git.commit": ...} to mlflow.start_run gave the run started with uv run log-run its commit, 1354555….
Additional Resources
- System Tags Reference — the
mlflow.tags and when MLflow sets them. - mlflow.start_run — the
tagsparameter.
