惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
O
OpenAI News
Cloudbric
Cloudbric
Attack and Defense Labs
Attack and Defense Labs
S
Secure Thoughts
J
Java Code Geeks
Help Net Security
Help Net Security
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
Security Archives - TechRepublic
Security Archives - TechRepublic
Hugging Face - Blog
Hugging Face - Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
GbyAI
GbyAI
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
H
Help Net Security
Google DeepMind News
Google DeepMind News
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
W
WeLiveSecurity
Stack Overflow Blog
Stack Overflow Blog
The GitHub Blog
The GitHub Blog
N
Netflix TechBlog - Medium
Jina AI
Jina AI
S
Security @ Cisco Blogs
月光博客
月光博客
Google Online Security Blog
Google Online Security Blog
P
Proofpoint News Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
TaoSecurity Blog
TaoSecurity Blog
MongoDB | Blog
MongoDB | Blog
WordPress大学
WordPress大学
F
Fortinet All Blogs
S
Securelist
M
MIT News - Artificial intelligence
V
Vulnerabilities – Threatpost
小众软件
小众软件
T
Tenable Blog
Y
Y Combinator Blog
T
Threat Research - Cisco Blogs
博客园 - 叶小钗
N
News | PayPal Newsroom
A
About on SuperTechFans
C
CERT Recently Published Vulnerability Notes
Cyberwarzone
Cyberwarzone
L
Lohrmann on Cybersecurity

Graphite blog

Introducing Code Tours: a new way to review Introducing Cursor Cloud Agents in Graphite Building the future of software development with Cursor Reimagining the PR Page: Designing for speed and focus Graphite changelog [11-20-2025] Graphite changelog [11-04-2025] Graphite changelog [10-16-2025] The future of engineering is collaborative (and already here) Meet Graphite Agent: the next evolution of AI code review Introducing frozen branches: A safer way to build on your teammates’ work Graphite changelog [09-17-2025] How we sped up code search for Graphite Chat Introducing Graphite Chat AI is writing code—here's why it also needs to review that code How I got Claude to write code I could actually ship How we built the first stack-aware merge queue (and why it matters) How we organize our monorepo to ship fast Graphite brings stacking to Tower Code review tooling: Should you build or buy? Making AI code review available to everyone Introducing: The new Graphite + Linear integration Graphite raises $52M and launches Diamond to reimagine code review for the age of AI Why AI will never replace human code review How stacked PRs unblock distributed development teams Graphite is going to Developer Week 2025 Beating the end of year code freeze How Graphite’s eng team ships code remarkably fast Why we chose Anthropic's Claude to power Graphite Reviewer AI code generation will remain fragmented How we redesigned Graphite's landing page in-house Introducing Graphite Reviewer: your AI code review companion How AI code review reduces review cycles to improve developer productivity What if you could get instant feedback on your code? The new developer toolchain Not Rocket Science - How Bors and Google’s TAP inspired modern merge queues Graphite's State of code review 2024 How Google migrated billions of lines of code from Perforce to Piper Going from 0 to 1: How to write better unit tests when there are none Speed up your merges: Parallel CI is now generally available for teams using Graphite’s merge queue Down for less than four minutes a month: how AWS deploys code BitKeeper, Linux, and licensing disputes: How Linus wrote Git in 14 days Graphite is now free for startups and open source projects Launch week wrap-up (May 2024) Reduce CI costs for Buildkite and GitHub Actions Cheaper CI & faster merging with batching How Google does code review The technical learning curve at a startup is gentler than you might think Graphite will now automatically rebase your partially-merged stacks Multiple engineers can now seamlessly collaborate on the same stack of PRs Do you ever outgrow GitHub? From the 80's to 2024 - how CI tests were invented and optimized Graphite changelog [4/10/2024] 🎺 Graphite changelog [4/25/2024] 🐸 How Stack Overflow replaced Experts Exchange How GitHub monopolized code hosting Graphite changelog [3/27/2024] 🤝 The core principles of building a good AI feature Onboarding roulette: deleting our employee accounts daily Graphite changelog [3/13/2024] 🚁 Why Facebook doesn’t use Git How to recreate the Phabricator code review workflow Types of code reviews: Improve performance, velocity, and quality What's the best GitHub pull request merge strategy? Phabricator vs GitHub vs Graphite: How do they stack up? Improving team velocity through better pull request practices Moving fast breaks things: the importance of a staging environment Building trust as a software engineer Keeping code simple: moving fast by avoiding over-engineering What's better than GitHub pull request filters? The Graphite pull request inbox 7 Best Phabricator alternatives for PR stacking + code review [2024] Accurate eng estimations: predicting and negotiating the future Tracking and understanding GitHub PR stats: A step-by-step guide 8 pull request best practices for optimal engineering What’s next for Graphite Graphite Q1 Launch week: Stacking with the tools you love Graphite Q1 Launch week: Making stacking seamless Accelerating code review The Mom Test How to use stacked PRs to unblock your entire team Graphite Q1 launch week 2024 The practical and philosophical problems with AI code review Empirically sup code review best practices Call site attribution: how to pinpoint rogue SQL queries throttling your performance Post mortem: we took 124 seconds from you, here's 378 back Your GitHub pull request workflow is slowing everyone down Optimizing CI/CD workflows for trunk-based development Why we use AWS instead of Vercel to host our Next.js app How large pull requests slow down development 3 key lessons in application server optimization Trunk-based development: why you should stop using feature branches Git was built in 5 days Why large companies and fast-moving startups are banning merge commits How long should your CI take? Experimenting with AI code review CRA to AppRouter in 5 Steps: A case study with Graphite Graphite Changelog [10/18/2023] The comprehensive guide to writing the best PR title of all time How 10,000 Developers All Contribute to the same Repo
Every engineer should understand git reflog
Harsh Siriah · 2023-12-12 · via Graphite blog

As a software engineer, you’ve probably wondered how Git’s reflog works under the hood. You (hopefully) won’t need to use reflog daily, but you’ve likely found yourself in a situation where your Git state is seemingly borked beyond repair at least once before. Engineers are (mostly) human, and Git mistakes can happen even with safeguards like pre-commit hooks in place. That’s where this guide comes in.

Today, we’ll be taking a look at ways to fix these mistakes with the power of git reflog. With reflog you can navigate the entire granular history of your Git repository to identify and fix any errors that find their way into your codebase.

What is Git reflog?

The Git reflog is a reference log file that stores a chronological list of all changes made to the HEAD pointer in your Git repository. HEAD always points to the most recent commit, and the reflog essentially tracks every previous commit ever made in the repo.

Think of the reflog as a logbook for your Git branches and other references. It records every change made to these references, enabling you to rewind time and undo any potentially unwanted actions. This can be incredibly helpful when you:

  • Accidentally commit something you shouldn't have.

  • Delete a commit or branch by mistake.

  • Need to recall what happened to a specific reference at a particular point in time.

This list is, of course, not exhaustive - I’m sure there are thousands of other mistakes you could possibly fix using reflog.

Locating the reflog:

To start, let’s actually take a look at the reflog and its various components.

Every repo has its own reflog stored in the .git folder at the root of your repository. In the .git directory, the reflog is stored in logs folder and is updated any time you make any changes to any branch (or other reference, like HEAD)

While the raw log contains a lot of useful info, it’s pretty ugly. Let’s look at how we can sift through the log and navigate it a little better.

Time qualifiers

Every action you take in Git is timestamped in the reflog, so, when you want to explore specific moments in your Git history, you can easily filter by various periods of time with “time qualifiers”.

These tokens serve as filters for navigating your reflog and allow you to specify a timeframe and view changes made within that window.

Here are a few examples:

  • @{1.minute.ago}: See the state of your repository just a minute ago.

  • @{1.hour.ago}: Rewind your Git journey by one hour.

  • @{1.day.ago}: Compare your current work with yesterday's progress.

  • @{yesterday}: Travel back to yesterday's snapshot of your repository.

  • @{1.week.ago}: Analyze changes made a week ago.

  • @{1.month.ago}: Recall the state of your project a month back.

  • @{1.year.ago}: Explore the evolution of your work over a year.

  • @{2023-10-21.08:30:00}: Jump to a specific date and time in your Git history.

Combining and stacking time qualifiers**:**

  • @{1.day.2.hours.ago}: Refine your search to a specific time within the past day.

  • @{5.minutes.ago}: Plural forms allow for even more precise navigation.

Using time qualifiers with other Git commands**:**

  • @{git diff main@{0} main@{1.day.ago}}: Compare your current main branch with its state one day ago.

  • @{git log master@{1.month.ago..yesterday}}: View all commits made to the master branch between one month ago and yesterday.

Using reflog: your guide to time travel

You can se the see a detailed history of changes made to the current branch (HEAD) or any other reference you specify using this command in your terminal:

To check if a particular entry exists in the reflog, you can use:

Go back in time:

You can also specify a specific point in the reflog using keywords like

  • HEAD@{2} (two revisions back)

  • master@{one.week.ago} (master's state one week ago).

This allows you to checkout that specific point and view the state of the world at that point in time any subsequent changes.

Clean up the past:

Because the reflog adds entries for every git event in your repo, it can get large very quickly. Luckily however, git has garbage collection built right in. The way this works is that many common Git commands silently run additional plumbing commands under the hood to prune the reflog. Two of these plumbing subcommands are expire and delete.

Expire

Expire prunes older reflog entries.

You can also manually remove old entries based on specified timeframes:

git reflog expire <time>

or

git reflog expire --expire-unreachable <time>

You can use the following options to customize the usage of this command:

  • --all: Process reflogs of all references.

  • --single-worktree: Limit processing to the current working tree only.

  • --expire=<time>: Prune entries older than a specified time.

  • --expire-unreachable=<time>: Prune unreachable entries older than a specified time.

  • --updateref: Update the reference to the top reflog entry if the previous top entry was pruned.

  • --rewrite: Adjust the "old" SHA-1 of reflog entries if their predecessors are pruned.

  • --stale-fix: Prune entries referencing "broken commits".

  • --dry-run: Show what would be pruned without actually deleting any entries.

  • --verbose: Display additional information on the screen.

Delete

To remove an individual entry from the reflog:

git reflog delete <entry>

You can use the following options to customize the usage of this command:

  • --updateref: Update the reference to the top reflog entry if the previous top entry was pruned.

  • --rewrite: Adjust the "old" SHA-1 of reflog entries if their predecessors are pruned.

  • --dry-run: Show what would be pruned without actually deleting any entries.

  • --verbose: Display additional information on the screen.

While these commands are important to understand, as an enduser you will typically never run them yourself as Git will run them under the hood.

Scenario: Correcting a Bad Rebase with Git Reflog

Imagine you're working on a feature branch in your project, and you initiate a rebase onto the main branch. However, something goes wrong during the rebase process—perhaps due to conflicts or incorrect conflict resolutions—and you end up with a feature branch that's in a worse state than before. This is a common situation that many developers face. Fortunately, git reflog can be a lifesaver in such instances, allowing you to restore your feature branch to its state before the rebase.

Here's how to fix a bad rebase:

1. Identify the Commit Before the Rebase:

To undo the effects of a bad rebase, first find the commit hash where your feature branch was before the rebase. The git reflog command will help you with this:

git reflog show <your-feature-branch>

This command shows a list of recent commits on your feature branch, including the state before the rebase. Look for the commit right before the rebase started.

Example output of the reflog might look like this:

52896f49 (HEAD -> feature) feature@{0}: rebase: Added new feature post-rebase

7896dbe feature@{1}: commit: Pre-rebase commit

43672ac feature@{2}: commit: Another feature update

987fd12 feature@{3}: commit: Initial feature work

Here, 7896dbe is the commit before the rebase started.

2. Revert to Pre-Rebase State:

Once you’ve identified the correct commit, use the following command to reset your feature branch to that state, effectively undoing the rebase:

Replace 7896dbe with the actual commit hash you identified. This resets your feature branch to how it was before the problematic rebase.

3. Verify the Branch State:

After running the git reset command, check that your feature branch is back to its desired state:

The top commit should now be the one you identified as the last correct commit before the rebase.

Conclusion

Remember that while the reflog is a powerful tool, it's not a substitute for good engineering practices. Practicing safe Git habits, and by making frequent small pull requests you can minimize the need for reflog interventions.

In a worst case scenario however, know thatreflog can be your saving grace.