Git – How to unstash only certain files?

Overview of Git

Git is an open-source distributed version control system for agile and efficient processing of any small or large project. This version control software developed by Linus Torvalds to help manage Linux kernel development.

Git is different from the commonly used version control tools CVS, Subversion, etc. It uses a distributed version repository method without server-side software support.

How to unstash only certain files?

Sometimes, I stashed my changes. But I want to unstash only some files from the stash later. How can I do this?

Let’s see the solution to unstash only certain files as following.

git checkout [email protected]{N}  

Eg. To restore only ./test.c file and ./include folder from last stashed,

git checkout [email protected]{0} ./test.c ./include

As commented: “unstash” (git stash pop), then:

  • add what you want to keep to the index (git add)
  • stash the rest: git stash –keep-index

Leave a Comment