Enable or disable Git tracking#
By default, Neptune automatically extracts the following information from the project's .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.
You can view the logged data in the Source code tab.
Specifying the repository path#
By default, Neptune looks for a repository in the execution path and its parent directories. You can also 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:
Disabling Git tracking#
To disable logging of any Git repository information:
You can also use the DISABLED
constant to turn off the logging:
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:
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", mode="read-only")
# Difference between index and HEAD
run["source_code/diff"].download()
run.stop()
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 andf8ef2c3
"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.
Related
- API reference ≫ Field types ≫
GitRef
- Logging source code