Chase AdamsChase Adams
AboutContentPromptsPlayground

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

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.

First Cohort
No Coding Experience Required

Build Your Website with AI—No Code Required

Learn to create and deploy professional websites using ChatGPT and Claude. Go from complete beginner to confident website builder.

Start Building Today

Post Details

Published
Nov 27, 2022
Category
Engineering
Share
Ask ChatGPT
Ask Claude

Latest Posts

Joining Rocket Money as VP of AI Engineering

Joining Rocket Money as VP of AI Engineering

Leading AI engineering at Rocket Money to write the playbook for how engineering teams operate in the AI era

AboutAI Workflow SpecContentStacksNewsletterPromptsRSS

Ask me anything

Loading...

Hi! Ask me anything about Chase's work.

I can answer questions based on his blog posts and articles.

Experimental: This chat is a side project I work on in my free time. Responses may vary in quality and accuracy.