Notion app logo
Struggling to stay organized and effective? Learn to master your time and tasks with the Effectively Notion course!

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

How to restore a file to a specific state with git.

2022-11-28

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.

Photo of Chase Adams

Hey, I'm Chase. I help aspiring entrepreneurs and makers turn their ideas into digital products and apps.

Freebies

Vector Arrow Scribbles
banner image for figma vector arrows scribbles

A figma community project of vectorized hand-drawn arrows.

Go To Figma
Vector Line Scribbles
banner for figma vector line scribbles

A figma community project of vectorized hand-drawn lines.

Go To Figma
Vector Shape Scribbles
banner image of figma vector shapes scribbles

A figma community project of vectorized hand-drawn shapes.

Go To Figma

Subscribe to my Newsletter

Every other week I publish the Curiously Crafted newsletter.

In it, I explore the intersection of curiosity and craft: the people who make stuff, what they make and the way they pursue the craft of making.

Online

I'm on almost all social media as @curiouslychase.

The curious logo of Chase Adams: glasses and a bow tie.stay curious.