> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vers.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Commit

# vers commit

Save the current state of a VM as a commit.

## Synopsis

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers commit                          # Commit current HEAD VM
vers commit <vm-id|alias>           # Commit specific VM
```

## Description

The `commit` command creates a snapshot of a VM's current state by saving it as a commit. This preserves the exact state of the VM at a specific point in time. You can commit either your current HEAD VM or specify a particular VM by ID or alias.

## Basic Usage

### Commit Current HEAD VM

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers commit
```

Creates a commit of whatever VM your HEAD currently points to.

### Commit Specific VM

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers commit vm-abc123
vers commit my-app-vm
```

Creates a commit of the specified VM by ID or alias.

## What Happens During Commit

1. **VM Identification**: Resolves the target VM (provided or HEAD)
2. **State Capture**: Creates a snapshot of the VM's current state
3. **Commit Creation**: Saves the commit via the API with a 60-second timeout

## Examples

### Development Workflow

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
# Commit current work in progress
vers commit

# Commit specific VM after testing
vers commit test-vm
```

### Release Process

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
# Commit production environment
vers commit production-vm
```

### Multiple Environment Commits

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
# Commit development environment
vers commit dev-env

# Commit staging environment
vers commit staging-env

# Commit production environment
vers commit prod-env
```

## Commit Output

When you commit, you'll see detailed information:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers commit my-app
Using provided VM: my-app
Creating commit for VM 'vm-abc123'
Creating commit...
Successfully committed VM 'my-app'
Commit ID: c1a2b3c4d5e6f7g8
```

The output includes:

* **Commit ID**: Unique identifier for this commit

## Using HEAD VM

When no VM is specified, the command uses your current HEAD:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
# Check your current HEAD
vers checkout
Current HEAD: my-dev-vm (State: Running)

# Commit it
vers commit
Using current HEAD VM: vm-def456
Creating commit for VM 'vm-def456'
...
```

## Error Scenarios

### VM Not Found

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers commit nonexistent-vm
# Error: failed to find VM: VM not found
```

**Solution**: Verify the VM ID/alias exists with `vers status`.

### No HEAD Set

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers commit
# Error: failed to get current VM: no HEAD set
```

**Solution**: Use `vers checkout <vm-id>` to set a HEAD, or specify a VM explicitly.

### Timeout

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers commit large-vm
# Error: failed to commit VM 'large-vm': context deadline exceeded
```

**Solution**: Commit operations have a 60-second timeout. Try again or check your network connection.

## Tips

* Commit before making risky changes to preserve known-good states
* Use descriptive VM aliases to identify important snapshots later
* You can restore from a commit using `vers run-commit`

## Common Patterns

### Commit and tag in one flow

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
COMMIT=$(vers commit --format json | jq -r .commit_id)
vers tag create production "$COMMIT"
```

### Snapshot before a risky change

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
# Safety net
SAFETY=$(vers commit --format json | jq -r .commit_id)

# ...try the risky thing...

# If it goes sideways, restore from the snapshot
vers run-commit "$SAFETY" --vm-alias recovery
```

### Promote one VM's state to another

Commit a VM, then boot the commit on a fresh (possibly differently-sized) VM:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
COMMIT=$(vers commit small-dev --format json | jq -r .commit_id)
vers run-commit "$COMMIT" --vm-alias prod --wait
```

## See Also

* [vers checkout](checkout) - Switch between VMs to commit different ones
* [vers status](status) - See available VMs and current HEAD
* [vers branch](branch) - Create new VMs from committed states
* [vers run-commit](run-commit) - Start environment from a commit
