Initial commit

This commit is contained in:
Zhongwei Li
2025-11-29 18:24:50 +08:00
commit 532dda1435
18 changed files with 2564 additions and 0 deletions

View File

@@ -0,0 +1,123 @@
---
name: Exploring Operation History in Jujutsu
description: Help users explore operation history and time travel in jj. Use when the user explicitly mentions 'operation log', 'op log', 'jj op', or 'operation history'. Covers jj op log, --at-op flag, op restore, and operation exploration.
allowed-tools: Bash(jj op log:*), Bash(jj op show:*), Bash(jj op restore:*), Bash(jj op diff:*), Bash(jj log --at-op:*), Bash(jj status:*), Bash(jj diff --at-op:*), Read(*/jj-operations/*.md)
---
# Exploring Operation History in Jujutsu
## Overview
**The operation log is your safety net.** Every repository-modifying command is recorded with complete snapshots, allowing full time travel and recovery.
**Key insight:** Each operation contains metadata (timestamp, user, command) plus a snapshot of all commit states, bookmarks, and repository structure.
## When to Use Operation Log
**Use operation log when:**
- ✅ You need to understand what you've been doing
- ✅ You want to find a specific past state
- ✅ You need to recover from complex mistakes
- ✅ You're debugging unexpected repository state
- ✅ You want to see history of changes to a commit
**Don't use operation log when:**
- ❌ You just need to undo the last operation (use `jj undo` from jj-undo skill)
- ❌ You're looking at commit history (use `jj log`)
- ❌ You want to see file changes (use `jj diff`)
## Core Capabilities
### 1. Viewing Operations (Read-Only)
Browse operation history and see what changed.
**Commands:** `jj op log`, `jj op show`, `jj op diff`
**When to use:** You want to understand what operations happened, what they changed, or compare repository states.
📚 **See detailed docs:** `viewing-operations.md`
### 2. Time Travel (Read-Only)
View the repository at any past operation without modifying current state.
**Commands:** `--at-op` flag with `jj log`, `jj status`, `jj diff`, etc.
**When to use:** You want to explore past states, compare with current state, or find the right operation to restore.
📚 **See detailed docs:** `time-travel.md`
### 3. Restoring to Past Operations
Jump the entire repository back to a specific operation state.
**Commands:** `jj op restore <op-id>`
**When to use:** You found the right past state and want to return to it, recovering from complex mistakes.
📚 **See detailed docs:** `restoring-operations.md`
### 4. Common Patterns & References
Operation references (@, @-), common workflows, best practices.
**When to use:** You need quick reference or want to learn common patterns.
📚 **See detailed docs:** `operation-patterns.md`
## Quick Command Reference
### Viewing
```bash
jj op log # Show operation history
jj op show <op-id> # Show operation details
jj op diff --from <a> --to <b> # Compare operations
```
### Time Travel (read-only)
```bash
jj log --at-op=<op-id> # View commit history at operation
jj status --at-op=<op-id> # View working copy at operation
```
### Restoring
```bash
jj op restore <op-id> # Jump to specific operation
jj op restore @- # Go back one operation (= jj undo)
```
## Integration with Undo
**Relationship:** Operation log is the foundation, undo is a convenience.
- `jj undo` = `jj op restore @-` (restore to parent operation)
- `jj undo` twice = `jj op restore @--` (go back 2 operations)
**When to choose each:**
- Quick recent mistake → `jj undo` (see jj-undo skill)
- Need to skip multiple operations → `jj op restore`
- Not sure which operation → Explore with `--at-op`, then restore
## Progressive Disclosure
This skill uses progressive disclosure to manage context efficiently:
1. **Start here** for overview and quick reference
2. **Read detailed docs** when you need specific guidance:
- `viewing-operations.md` - How to browse and understand operation log
- `time-travel.md` - How to explore past states without changing anything
- `restoring-operations.md` - How to restore to past operations and recover
- `operation-patterns.md` - Common patterns, references, and best practices
Claude will automatically load the relevant detailed documentation when helping you with specific operation log tasks.
## Remember
**Operation log is your time machine.** Everything is recorded, everything is explorable, everything is restorable. You can't lose work in jj.

View File

@@ -0,0 +1,264 @@
# Operation Patterns and References
This document covers operation references, common patterns, and best practices for working with the operation log.
## Operation References
### Symbolic References
**Current operation:** `@`
```bash
jj op show @ # Show current operation
```
**Parent operations:** `@-` (immediate parent), `@--` (grandparent)
```bash
jj op show @- # Previous operation
jj op restore @- # Go back one operation (like jj undo)
jj op restore @-- # Go back two operations
jj op restore @---- # Go back 4 operations
```
**Note:** No child operation syntax (`@+`) because operations form a tree, not a line.
### Using References in Commands
```bash
# Show operations
jj op show @ # Current
jj op show @- # Previous
jj op show @-- # Two back
# Restore operations
jj op restore @- # = jj undo
jj op restore @--- # Go back 3 operations
# Compare operations
jj op diff --from @--- --to @
```
## Common Patterns
### Pattern: "What Did I Just Do?"
See recent operations and current operation details:
```bash
jj op log --limit 5 # Recent operations
jj op show @ # Current operation details
```
### Pattern: "Find When Things Broke"
Bisect through time to find when things went wrong:
```bash
jj op log # Browse operations
# Bisect through time with --at-op
jj log --at-op=<candidate>
# Find last good state, restore to it
```
### Pattern: "Compare Now vs Then"
See all changes between a past operation and now:
```bash
jj op log # Find old operation
jj op diff --from <old> --to @ # See all changes
```
### Pattern: "Undo Multiple Operations"
Two approaches to go back several operations:
```bash
# Option 1: Multiple undo
jj undo
jj undo
jj undo
# Option 2: Direct restore (faster)
jj op log
jj op restore @--- # Go back 3 operations
```
### Pattern: "Explore Before Committing"
Use time travel to explore safely before restoring:
```bash
# 1. Browse operations
jj op log
# 2. Explore candidates with --at-op
jj log --at-op=abc123 # Candidate 1
jj log --at-op=def456 # Candidate 2
jj log --at-op=ghi789 # Found it!
# 3. Now commit to the restore
jj op restore ghi789
```
### Pattern: "See What Changed Between Two Operations"
Compare repository state between any two operations:
```bash
jj op log # Find two operations of interest
jj op diff --from abc123 --to def456
```
## Best Practices
### When to Use Operation Log
**Use operation log when:**
- ✅ You need to understand what you've been doing
- ✅ You want to find a specific past state
- ✅ You need to recover from complex mistakes
- ✅ You're debugging unexpected repository state
- ✅ You want to see history of changes to a commit
**Don't use operation log when:**
- ❌ You just need to undo the last operation (use `jj undo`)
- ❌ You're looking at commit history (use `jj log`)
- ❌ You want to see file changes (use `jj diff`)
### Exploration First, Restore Second
**Best practice:** Use `--at-op` to explore before using `jj op restore`:
```bash
# ✅ Good: Explore first
jj log --at-op=abc123 # Check if this is right
jj op restore abc123 # Commit to it
# ❌ Risky: Restore without checking
jj op restore abc123 # Hope this is right!
```
### Use Operation References for Recent Operations
For recent operations, use symbolic references instead of IDs:
```bash
# ✅ Good: Clear and concise
jj op restore @- # Go back one
jj op restore @-- # Go back two
# ❌ Verbose: Looking up IDs
jj op log # Find ID
jj op restore abc123def456 # Use ID
```
### Check Status After Restore
Always verify state after restoring:
```bash
jj op restore abc123
jj status # Check working copy
jj log # Check commit history
```
## Integration with Other Workflows
### With jj-undo Skill
**Relationship:** Operation log is the foundation, undo is a convenience.
```bash
# These are equivalent:
jj undo # Simple
jj op restore @- # Explicit
# These are equivalent:
jj undo && jj undo # Multiple undo
jj op restore @-- # Direct restore
```
**When to choose each:**
- Quick recent mistake → `jj undo`
- Need to skip multiple operations → `jj op restore`
- Not sure which operation → Explore with `--at-op`, then restore
### With Stack-Based Workflow
Use operation log to recover from stacking mistakes:
```bash
jj new # Start new commit
jj describe -m "message" # Oops, not ready
jj op log # Find operation before jj new
jj op restore @-- # Go back before new
```
### With Plan-Driven Workflow
Use operation log to recover plan commits:
```bash
jj describe -m "impl: feature" # Oops, lost the plan
jj op log # Find operation with plan
jj op restore abc123 # Restore plan commit
```
## Quick Reference Card
### Viewing Operations
```bash
jj op log # Show operation history
jj op log --limit 20 # Last 20 operations
jj op show <op-id> # Show operation details
jj op show @ # Show current operation
jj op diff --from <a> --to <b> # Compare operations
```
### Time Travel (Read-Only)
```bash
jj log --at-op=<op-id> # View commit history at operation
jj status --at-op=<op-id> # View working copy at operation
jj diff --at-op=<op-id> # View changes at operation
```
### Restoring
```bash
jj op restore <op-id> # Jump to specific operation
jj op restore @- # Go back one (= jj undo)
jj op restore @-- # Go back two operations
jj op restore @--- # Go back three operations
```
### Operation References
```bash
@ # Current operation
@- # Previous operation
@-- # Two operations ago
@--- # Three operations ago
```
## Remember
**Operation log is your time machine:**
- Everything is recorded
- Everything is explorable
- Everything is restorable
- You can't lose work in jj
**Progressive approach:**
1. View operations with `jj op log`
2. Explore safely with `--at-op`
3. Restore confidently with `jj op restore`
4. Verify with `jj status` and `jj log`

View File

@@ -0,0 +1,221 @@
# Restoring to Past Operations
This document covers how to restore the repository to past operations and recover from complex mistakes.
## The `jj op restore` Command
**Purpose:** Return the entire repository to the state at a specific operation.
**Key concept:** This is **actual time travel**. You're changing your repository state, not just viewing.
### What It Does
- Restores all commits to their state at that operation
- Updates bookmarks to their past positions
- Restores working copy to match that operation
- Creates a NEW operation recording this restoration
**Important:** `jj op restore` is itself an operation, so it's also undoable with `jj undo`.
## Basic Restore Workflow
### 1. Find the Operation You Want
```bash
jj op log
```
### 2. Restore to That Operation
```bash
jj op restore abc123def456
```
### 3. Verify the Restoration
```bash
jj status
jj log
```
## Example: Recovering from Bad Squash
```bash
# Oh no, squashed wrong commits!
jj op log # Find operation before squash
# See: xyz789abc123 was before the bad squash
jj op restore xyz789abc123 # Jump back before mistake
# Repository now as it was before squash
```
## Finding the Right Operation to Restore
See `time-travel.md` for exploration techniques using `--at-op` to find the right operation before committing to a restore.
### Strategy 1: By Time (Recent Mistake)
```bash
jj op log --limit 10 # Show last 10 operations
# Look for operation just before mistake
# Restore to that operation
```
### Strategy 2: By Command (Find Specific Action)
```bash
jj op log | grep "squash" # Find all squash operations
jj op log | grep "describe"# Find all describe operations
# Identify the problematic operation
# Restore to operation before it
```
### Strategy 3: By Exploration (Step Through History)
```bash
# Use --at-op to explore without committing
jj op log
jj log --at-op=abc123 # Is this the right state?
jj log --at-op=def456 # Or this one?
jj log --at-op=ghi789 # Found it!
jj op restore ghi789 # Now actually restore
```
## Complex Recovery Scenarios
### Scenario 1: Multiple Bad Operations
**Problem:** Made several mistakes in a row, need to go back before all of them.
**Solution:**
```bash
# 1. Find operations
jj op log --limit 20
# 2. Identify last good operation
jj log --at-op=<candidate> # Explore candidates
# 3. Restore to last good state
jj op restore <last-good-op>
```
### Scenario 2: Not Sure Which Operation to Restore
**Problem:** Complex history, unclear which operation to restore to.
**Solution - Use time travel to explore:**
```bash
# 1. Start with operation log
jj op log
# 2. Use --at-op to peek at different states
jj log --at-op=abc123
jj status --at-op=abc123
jj diff --at-op=abc123
# 3. Try different operations until you find the right one
jj log --at-op=def456
jj log --at-op=ghi789
# 4. When you find it, restore
jj op restore ghi789
```
### Scenario 3: Want to See Specific Change
**Problem:** Need to understand what a particular operation did.
**Solution:**
```bash
# 1. Find the operation
jj op log | grep "squash" # or other command
# 2. Show what it changed
jj op show abc123def456
# 3. Compare before/after
jj log --at-op=abc123@- # Before
jj log --at-op=abc123 # After
# 4. See diff
jj op diff --op abc123
```
### Scenario 4: Concurrent Operations (Advanced)
**Problem:** Multiple jj commands ran concurrently, created divergent operations.
**What happened:** Jj is lock-free, so concurrent operations create separate branches in the operation log.
**Solution:**
```bash
# 1. View operation log - will show divergence
jj op log
# 2. Identify which branch is correct
jj log --at-op=<branch1>
jj log --at-op=<branch2>
# 3. Restore to correct branch
jj op restore <correct-branch>
```
## Safety Considerations
### Restore is Undoable
Since `jj op restore` creates a new operation, you can undo it:
```bash
jj op restore abc123 # Restore to operation
# Oops, that was wrong
jj undo # Undo the restore
```
### What Restore Affects
**Does affect:**
- ✅ All commits and their states
- ✅ Bookmark positions
- ✅ Working copy files (updates to match restored state)
- ✅ Repository structure
**Does NOT affect:**
- ❌ The operation log itself (restore is recorded)
- ❌ Remote repositories until you push
- ❌ Other people's concurrent operations
### You Can't Lose Work
Even after restoring, the "future" operations still exist in the operation log. You can always restore forward again:
```bash
jj op restore abc123 # Go back
# Do some work...
jj op log # See all operations, including "future" ones
jj op restore def456 # Restore to future state
```
## When to Use Restore vs Undo
**Use `jj undo`** (see jj-undo skill):
- Quick recent mistake (1-2 operations ago)
- Simple, immediate reversal
**Use `jj op restore`:**
- Need to jump back multiple operations at once
- Know the specific operation ID you want
- Want to skip over several intermediate operations
- Complex recovery from multiple mistakes
**Relationship:**
- `jj undo` = `jj op restore @-` (restore to parent operation)
- `jj undo` twice = `jj op restore @--` (go back 2 operations)

View File

@@ -0,0 +1,135 @@
# Time Travel: Viewing Past States
This document covers how to explore the repository at past operations without modifying your current state.
## The `--at-op` Flag
**Purpose:** View the repository as it was at any past operation without changing current state.
**Key concept:** This is **read-only time travel**. You're peeking at history, not modifying anything.
## Works with Read-Only Commands
The `--at-op` flag can be used with any read-only jj command:
```bash
jj log --at-op=<op-id> # See commit history at that operation
jj status --at-op=<op-id> # See working copy state
jj diff --at-op=<op-id> # See changes at that time
jj show --at-op=<op-id> # See specific commit at that time
```
**Important:** Working copy is **NOT** modified. You're just viewing how things were.
## Basic Exploration Workflow
### 1. Find Operation of Interest
```bash
jj op log # Browse operation history
```
### 2. View Repo State at That Operation
```bash
jj log --at-op=abc123def456
```
### 3. Compare with Current State
```bash
jj log # Current state
jj log --at-op=abc123 # Past state
```
### 4. See What Changed in Working Copy
```bash
jj diff --at-op=abc123
```
## Exploring to Find Right Restore Point
**Problem:** You know something went wrong, but not sure which operation to restore to.
**Solution:** Use `--at-op` to explore without committing:
```bash
# 1. Start with operation log
jj op log
# 2. Use --at-op to peek at different states
jj log --at-op=abc123 # Is this the right state?
jj status --at-op=abc123 # Check working copy
jj diff --at-op=abc123 # See changes
# 3. Try different operations until you find the right one
jj log --at-op=def456 # Or this one?
jj log --at-op=ghi789 # Found it!
# 4. When you find it, restore (see restoring-operations.md)
jj op restore ghi789 # Now actually restore
```
## Time Travel Patterns
### "Find When Things Broke"
```bash
jj op log # Browse operations
# Bisect through time with --at-op
jj log --at-op=<candidate>
jj log --at-op=<earlier>
jj log --at-op=<evenEarlier>
# Find last good state, then restore to it
```
### "Compare Now vs Then"
```bash
# View current state
jj log
jj status
# View past state
jj log --at-op=abc123
jj status --at-op=abc123
# Compare
jj op diff --from abc123 --to @
```
### "See Commit History Evolution"
```bash
# How did the log look after each operation?
jj log --at-op=abc123 # After operation 1
jj log --at-op=def456 # After operation 2
jj log --at-op=ghi789 # After operation 3
```
## Advantages of Time Travel
**Safe exploration:**
- ✅ No risk of breaking current state
- ✅ Try multiple candidates before committing
- ✅ Understand what changed between operations
- ✅ Make informed decisions about restoring
**When to use:**
- Not sure which operation to restore to
- Want to understand history before taking action
- Debugging complex repository states
- Learning how operations affected the repository
## Important Notes
**Automatic snapshotting is disabled:** When using `--at-op`, jj doesn't snapshot the working copy before the command.
**Read-only only:** You cannot modify the repository while viewing at a past operation. Use `jj op restore` for that (see restoring-operations.md).
**No working copy modification:** Your files on disk don't change. You're viewing metadata about how the repo was structured at that point.

View File

@@ -0,0 +1,139 @@
# Viewing Operations in Jujutsu
This document covers how to browse and understand the operation log using read-only viewing commands.
## Browsing Operation History
### `jj op log` - View All Operations
**Basic usage:**
```bash
jj op log # Show recent operations
jj op log --limit 20 # Show last 20 operations
jj op log --no-graph # Show without graph visualization
```
**What you'll see:**
- Operation ID (12-character hash)
- Timestamp and duration
- Username and hostname
- Command that was executed
- High-level description of changes
**Example output interpretation:**
```
@ abc123def456 user@host 2025-01-05 14:23:45 -08:00
│ jj squash
│ squash commit xyz into abc
◉ 789ghi012jkl user@host 2025-01-05 14:20:12 -08:00
│ jj describe -m "Add feature"
│ describe commit xyz
```
**Reading the log:**
- `@` marks the current operation (where you are now)
- Most recent operations at top
- Each operation shows what command created it
- Graph shows operation relationships
## Exploring What Changed
### `jj op show <op-id>` - See Operation Details
**Purpose:** Understand exactly what a specific operation changed.
**Usage:**
```bash
jj op show abc123def456 # Show what operation did
jj op show @ # Show current operation
jj op show @- # Show previous operation
```
**What you'll see:**
- Operation metadata
- Which commits were modified
- What changed in each commit
- Bookmark movements
- Working copy changes
### `jj op diff` - Compare Repository States
**Purpose:** See differences between two operations or current vs past.
**Usage:**
```bash
# Compare current state with past operation
jj op diff --from abc123 --to @
# Compare two past operations
jj op diff --from abc123 --to def456
# See what operations changed
jj op diff --op abc123
```
**Use cases:**
- Understanding what went wrong between two points
- Seeing cumulative effect of several operations
- Debugging complex history issues
## Finding Operations
### By Time (Recent Mistakes)
```bash
jj op log --limit 10 # Show last 10 operations
# Look for operation just before mistake
```
### By Command (Specific Actions)
```bash
jj op log | grep "squash" # Find all squash operations
jj op log | grep "describe"# Find all describe operations
# Identify the problematic operation
```
### By Description (What You Were Doing)
```bash
# Operation log shows what you ran
jj op log
# Look for descriptions like:
# "snapshot working copy" → Auto-snapshots
# "jj describe" → Commit descriptions
# "jj new" → Stack operations
# "jj squash" → Squash operations
```
## Common Viewing Patterns
### "What Did I Just Do?"
```bash
jj op log --limit 5 # Recent operations
jj op show @ # Current operation details
```
### "What Changed in This Operation?"
```bash
jj op show abc123def456 # Show specific operation details
jj op diff --op abc123 # See the diff
```
### "Compare Two Points in Time"
```bash
jj op log # Find two operations
jj op diff --from abc123 --to def456 # Compare them
```