Chase AdamsChase Adams
AboutContentPromptsPrototypesNewsletter

Reset specific file to its state on a commit or branch with git

Essays and updates on product, engineering, and AI by Chase Adams.

1 minute read

Post Details

Published
Nov 27, 2022
Category
Engineering
Share
ChatGPT

Latest Posts

A 2x2 Framework for Navigating AI Disruption

A 2x2 Framework for Navigating AI Disruption

Not all change requires the same response. A new framework for diagnosing which kind of disruption you're facing—and choosing the right strategy.

If you are working on a file that's version controlled with git and you realize, "whoops! I want to reset that file back to the way it was in a specific commit" or "I want to reset that file back to its state in my mainline branch", the command you want to use is checkout.

Let's say I want to reset a file named some/changed/file.ts back to the state it was in on my main branch, I would run:

 git checkout origin/main some/changed/file.ts 

This would restore the file back to the state it was originally in. If you've committed changes to it, you'll see that your git status shows that the file has changed by adding anything back and removing anything that was added.

AboutAI Workflow SpecContentStacksNewsletterPromptsRSS