Commit operation types for file manipulation.
Operations represent changes to be made in a single commit:
Add- Upload or update a fileDelete- Remove a file or folderCopy- Copy an existing LFS file (efficient, no re-upload)
Examples
# Add a file from disk
add_op = HfHub.Commit.Operation.add("model.bin", "/path/to/model.bin")
# Add from binary content
add_op = HfHub.Commit.Operation.add("config.json", ~s({"hidden_size": 768}))
# Delete a file
del_op = HfHub.Commit.Operation.delete("old_model.bin")
# Delete a folder
del_op = HfHub.Commit.Operation.delete("old_weights/", is_folder: true)
# Copy an LFS file
copy_op = HfHub.Commit.Operation.copy("v1/model.bin", "v2/model.bin")
Summary
Functions
Creates an add operation from a file path or binary content.
Gets base64-encoded content (for regular uploads).
Creates a copy operation for an existing LFS file.
Creates a delete operation.
Checks if content is from a file path vs binary data.
Gets the content as binary (reads file if path).
Types
Functions
@spec add(String.t(), binary() | Path.t(), keyword()) :: HfHub.Commit.Operation.Add.t()
Creates an add operation from a file path or binary content.
Automatically computes UploadInfo (SHA256, size, sample) for the content.
Options
:upload_info- Pre-computed upload info (skips computation)
Examples
# From file path
op = Operation.add("model.safetensors", "/path/to/model.safetensors")
# From binary
op = Operation.add("config.json", Jason.encode!(%{hidden_size: 768}))
@spec base64_content(HfHub.Commit.Operation.Add.t()) :: {:ok, String.t()} | {:error, term()}
Gets base64-encoded content (for regular uploads).
@spec copy(String.t(), String.t(), keyword()) :: HfHub.Commit.Operation.Copy.t()
Creates a copy operation for an existing LFS file.
Copy operations are efficient because they don't re-upload the file content. The file must already exist in the repository (or at src_revision).
Options
:src_revision- Source revision (default: current HEAD)
Examples
Operation.copy("v1/model.bin", "v2/model.bin")
Operation.copy("model.bin", "archive/model.bin", src_revision: "v1.0")
@spec delete( String.t(), keyword() ) :: HfHub.Commit.Operation.Delete.t()
Creates a delete operation.
Options
:is_folder- Set to true to delete a folder and contents
Examples
Operation.delete("old_model.bin")
Operation.delete("old_weights/", is_folder: true)
@spec file_path?(HfHub.Commit.Operation.Add.t()) :: boolean()
Checks if content is from a file path vs binary data.
@spec get_content(HfHub.Commit.Operation.Add.t()) :: {:ok, binary()} | {:error, term()}
Gets the content as binary (reads file if path).