Child pages
  • Getting Started with Git

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: checking out of stash. very cool!

...

Code Block
git reset --hard

Stash to Clean and Checkout from Stash to Work

Say that you have several different things going on in your project at any one time. How can you seperate them to check something in? You know about the "git stash" command, which cleans up your project. But what if you want part of the dirtiness, but not all of it?

Suppose you have file1.java, file2.java, file3.java, and file4.java. You have a single feature implemented in file1.java and file3.java and those edits stand on their own. If you are going to check in just file1.java and file3.java, you should test them on their own, without your other changes. First, do a "git stash". A "git status" will show you have no staged changes. Now do:

Code Block

git checkout stash@{0} -- file1.java
git checkout stash@{0} -- file3.java

Now you have your two files and not the others and you can build and test them in a clear project before you check them in!
One odd thing I noticed is this. The "git diff" you were doing before the stash will show your changes. Now you have to do "git diff HEAD". Not completely sure why, but there it is.