Restore blobs from git

Problem

Often thoughts come faster than actions, and once again I fell into this situation where I added files to the stage but forgot to commit, and immediately ran off to jump through commits using git reset and git checkout.

For those who are not yet familiar with this problem, git reflog won't help here. If you haven't done git add ., your last hope to recover files is only through:

  • Time Machine
  • Local changes if you're working in a JetBrains IDE
  • Or if you're good at recovering data from an SSD
  • etc

Solution

The solution is available if you did git add .. This means Git has stored the blobs in its database but hasn't linked them to a specific commit. We can view these blobs:

git fsck --full --unreachable --no-reflog

This command will return all unstructured blobs that have no index.

We can examine each of them individually.

git cat-file -p <hash>

and save them to some file:

git cat-file -p <hash> > file.txt

But, as you've already guessed, this is not very convenient.

Tooling

Let's create a more convenient script that does all this for us.


# Create a folder for recovered files
mkdir -p restored_blobs

# Find all dangling blobs and recover them
echo "Searching for lost files..."

# git fsck finds lost objects
# grep "dangling blob" filters only files (ignoring lost trees/commits)
# awk '{print $3}' extracts the hash
for blob in $(git fsck --lost-found | grep "dangling blob" | awk '{print $3}'); do
    echo "Recovering: $blob"
    git cat-file -p $blob > restored_blobs/$blob
done

echo "Done! Check the restored_blobs folder."

That's all. Now we just need to go through the files, figure out what's what, and put them where they originally were. Since the paths where they were located are not preserved, we'll have to do this manually.

Conclusions

I hope this saves someone's life, because it has saved mine many times.

Automating Project Workflows with YouTrack JavaScript Rules

Introduction

JetBrains YouTrack provides a powerful workflow engine that allows teams to automate and enforce project management policies using JavaScript. Unlike simple status transitions, YouTrack workflows can validate data, enforce business rules, and ensure consistency across your development process.

This article explores practical workflow automation through three real-world examples: validating test environment deployments, enforcing time tracking, and ensuring task estimation. These patterns are applicable to any team using YouTrack for agile development.

Why Workflow Automation?

Manual enforcement of project policies is error-prone and time-consuming. Common problems include:

  • Incomplete time tracking: Developers forget to log spent time
  • Missing estimations: Tasks move to "In Progress" without effort estimates
  • Incorrect state transitions: Test builds deployed to production accidentally
  • Inconsistent processes: Different team members follow different workflows

YouTrack's JavaScript-based workflows solve these problems by:

  1. Preventing invalid transitions: Block state changes that violate policies
  2. Enforcing required fields: Ensure critical data is captured
  3. Validating business logic: Implement complex rules programmatically
  4. Providing immediate feedback: Show clear error messages to users
Read more  ↩︎