Alexey
Alexey

Reputation: 9447

Git reset and checkout by single command

Consider I've staged for committing a file (e.g. db/schema.rb) that I didn't intended to change. I need to do:

git reset db/schema.rb
git checkout db/schema.rb

Can I do it by single command?

Upvotes: 23

Views: 1447

Answers (2)

habitats
habitats

Reputation: 2461

I just added this to my .zshrc / .bashrc

checkout() {
  git reset "*$1*"
  git checkout "*$1*"
} 

And then you can just do checkout <file> and you're all set.

Upvotes: 1

Ethan Zhang
Ethan Zhang

Reputation: 4479

I tried this one and works well for me:

git checkout HEAD -- path

Upvotes: 30

Related Questions