Skip to content

Log Git info#

If you have Git initialized in your project, Neptune extracts the following information from the .git directory:

  • Dirty: whether the working tree has local changes that have not been committed to the current branch.
  • Diff: a diff.patch file representing uncommitted changes.
  • Commit message: the message of the last commit.
  • Commit ID: Git SHA-1 value of the commit.
  • Commit author: the author of the last commit.
  • Commit date: the date of the last commit.
  • Current branch: the currently checked out Git branch.
  • Remotes: list of Git remotes your local .git is connected to.

By default, Neptune looks for a repository in the execution path and its parent directories.

You can view the logged data in the Source code tab of the run details view.

Specifying the repository path#

If the repository you want to track is not in the execution path, you can specify a custom path with the repository_path argument of GitRef:

import neptune
from neptune.types import GitRef

run = neptune.init_run(git_ref=GitRef(repository_path="/path/to/repo"))
Windows note

To correctly parse a Windows path (C:\Path\to\repo), you need to escape the backslashes.

For example, convert the file path to a raw string:

run = neptune.init_run(git_ref=GitRef(repository_path=r"C:\Path\to\repo"))

Disabling Git tracking#

To disable logging of any Git repository information:

import neptune

run = neptune.init_run(git_ref=False)

You can also use the DISABLED constant to turn off the logging:

import neptune
from neptune.types import GitRef

run = neptune.init_run(git_ref=GitRef.DISABLED)

Tracking uncommitted changes#

Neptune tracks uncommitted changes in the local repository by generating a diff.patch file from the difference between the index (current state of the repository, both staged and unstaged changes) and HEAD.

The diff file is logged under the "source_code/diff" field.

What happens if a run is resumed?

If you resume an existing run, the diff files are overwritten.

If you want to work around this in order to keep the original diff, you can upload it manually under a separate field:

git diff HEAD > uncommitted_changes.patch

Just make sure not to use this code again when resuming the run, as that would also overwrite the field.

Downloading the diff file#

You can download the diff.patch file with the download() method:

import neptune

run = neptune.init_run(with_id="CLS-32")

# Difference between index and HEAD


If HEAD and remote tracking branch point to different commits#

If your current branch and its upstream or remote tracking branch don't point to the same commit, Neptune logs two different diffs:

  • The diff between the index and HEAD (typically the tip of the branch you're on, unless you've set the HEAD to point elsewhere).
  • The diff between the index and most recent commit of the remote tracking branch (origin/<branch-name>).

For example, if you're working on a branch named dev and have uncommitted changes on top of the following Git log when creating the Neptune run:

* f8ef2c3 (HEAD -> dev) update dataset
* 8e80fb7 fix typo
* 25ba710 (origin/dev) format code
* 611d02f change batch size
* ...

then Neptune logs the following diff files:

  • "source_code/diff": The diff between the index and f8ef2c3
  • "source_code/diff_upstream_25ba710666df78be898fd935b1e55a3542837a98": The diff between the index and most recent commit of the remote tracking branch (origin/dev)

You can download the upstream diff file by using the full field name.