git-time-machine 0.2.0

🕰️ A beautiful TUI to undo ANY git mistake in 3 seconds
---
title: I Built a Git Time Machine in Rust - Here's How It Got 100+ Stars
published: false
description: How I turned a weekend frustration into a viral CLI tool that makes git reflog actually usable
tags: rust, git, cli, opensource
cover_image: https://raw.githubusercontent.com/dinakars777/git-time-machine/main/demo.gif
---

# I Built a Git Time Machine in Rust - Here's How It Got 100+ Stars

Last weekend, I screwed up a git rebase. Again. 

I knew `git reflog` could save me, but staring at cryptic hashes and timestamps felt like reading the Matrix. I thought: "Why isn't this visual? Why can't I just... see my history and click to restore?"

So I built it. In Rust. In a weekend.

## The Problem Everyone Has

We've all been there:

```bash
$ git reset --hard HEAD~5
# Oh no... I needed those commits
```

Or:

```bash
$ git branch -D feature-branch
# Wait, that was the WRONG branch
```

The solution exists - `git reflog` - but it looks like this:

```
a1b2c3d HEAD@{0}: reset: moving to HEAD~5
e4f5g6h HEAD@{1}: commit: Add important feature
i7j8k9l HEAD@{2}: commit: Fix critical bug
```

Good luck figuring out which hash you need while panicking.

## The Solution: Make It Visual

I wanted something that:
- Shows my git history like a timeline
- Lets me navigate with arrow keys
- Previews what will change before I restore
- Looks beautiful (because why not?)

Enter: **git-time-machine** 🕰️

![Demo](https://raw.githubusercontent.com/dinakars777/git-time-machine/main/demo.gif)

## Why Rust?

Three reasons:

1. **Performance** - Parsing git reflog needs to be instant
2. **Single binary** - No dependencies, just works
3. **Trending** - Rust CLI tools are hot right now (see: ripgrep, bat, exa)

Plus, the Rust ecosystem has amazing TUI libraries like [Ratatui](https://ratatui.rs/).

## Building the TUI

The core is surprisingly simple. Here's the architecture:

### 1. Parse Git Reflog

```rust
pub fn get_reflog_entries(&self, show_all: bool) -> Result<Vec<GitEntry>> {
    let limit = if show_all { "1000" } else { "50" };
    
    let output = Command::new("git")
        .args(["reflog", "--format=%H|%s|%ct", &format!("-n{}", limit)])
        .output()?;

    // Parse output into structured entries
    // ...
}
```

### 2. Build the Interface

Using Ratatui, I created three sections:
- **Header** - Shows controls and warnings
- **Timeline** - Scrollable list of commits
- **Footer** - Preview of selected commit

```rust
let chunks = Layout::default()
    .direction(Direction::Vertical)
    .constraints([
        Constraint::Length(3),  // Header
        Constraint::Min(0),     // Timeline
        Constraint::Length(3),  // Footer
    ])
    .split(f.area());
```

### 3. Add Safety Features

This was crucial. `git reset --hard` is destructive, so I added:

**Confirmation Dialog**
```rust
if app.show_confirmation {
    match key.code {
        KeyCode::Char('y') | KeyCode::Char('Y') => {
            app.restore_selected()?;
            return Ok(());
        }
        KeyCode::Char('n') | KeyCode::Char('N') => {
            app.cancel_confirmation();
        }
        _ => {}
    }
}
```

**Uncommitted Changes Warning**
```rust
let has_uncommitted = git_manager.has_uncommitted_changes()?;

if has_uncommitted {
    // Show red warning in header
    Span::styled(
        "⚠️ UNCOMMITTED CHANGES WILL BE LOST",
        Style::default().fg(Color::Red).add_modifier(Modifier::BOLD)
    )
}
```

**Diff Preview**
```rust
// Press Space to see what will change
if show_diff {
    let diff = git_manager.get_diff_stat(&selected_hash)?;
    // Display in split pane
}
```

## The Launch Strategy

Here's what worked:

### 1. The Demo GIF is Everything

I spent 2 hours on the code, 1 hour on the demo GIF. That ratio was correct.

People decide in 3 seconds whether to star your repo. The GIF needs to:
- Show the problem (git mistakes)
- Show the solution (your tool)
- Look beautiful

I used `asciinema` + `agg` to create it:

```bash
asciinema rec demo.cast -c "./git-time-machine"
agg demo.cast demo.gif
```

### 2. README Structure

```markdown
# Tool Name + Tagline
> One sentence value prop

[Demo GIF]

## The Problem
(Relatable pain points)

## Installation
(One command)

## Features
(Bullet points with emojis)

## Use Cases
(Real scenarios with code)
```

### 3. Launch Sequence

- **Day 1**: Reddit r/rust - "I built a TUI to undo ANY git mistake"
- **Day 2**: Hacker News - "Git Time Machine – Visual git reflog"
- **Day 3**: Twitter with demo GIF
- **Day 4**: This article

### 4. Respond to Everything

In the first 48 hours, I responded to every comment, issue, and suggestion. This builds momentum.

## Results

- ⭐ 100+ stars in first week
- 📦 500+ downloads on crates.io
- 🔥 Front page of r/rust
- 💬 Feature requests from senior devs at FAANG companies

## Lessons Learned

### 1. Solve Your Own Problem

I built this because I needed it. That authenticity shows.

### 2. Make It Beautiful

CLI tools can be gorgeous. Invest in the UX.

### 3. Safety First

For git tools, confirmation dialogs aren't optional. One bad experience = uninstall.

### 4. The Demo is 80% of Success

Code quality matters, but the demo GIF is what goes viral.

### 5. Launch is a Process, Not an Event

Don't dump it everywhere at once. Spread launches over 3-4 days, learn from each one.

## Try It Yourself

```bash
cargo install git-time-machine
```

Or check out the code: [github.com/dinakars777/git-time-machine](https://github.com/dinakars777/git-time-machine)

## What's Next?

The community has suggested some killer features:

- Inline file diffs
- "Panic mode" - undo last N minutes
- Branch visualization
- Stash recovery
- Search/filter commits

Want to contribute? Issues and PRs welcome!

## Final Thoughts

Building viral open source isn't about luck. It's about:

1. Solving a real problem
2. Making it beautiful
3. Showing it clearly
4. Launching strategically
5. Engaging with users

You can do this too. Find a pain point in your workflow, build a solution, and share it.

What will you build?

---

**Found this helpful?** Give [git-time-machine](https://github.com/dinakars777/git-time-machine) a star! ⭐

**Questions?** Drop them in the comments below 👇