Changes for page Getting Started with Git

Last modified by Bastian Triller on 2013/05/21 17:24

From version 210.1
edited by Kieran Kelleher
on 2012/01/20 08:26
Change comment: less is more
To version 211.1
edited by Ray Kiddy
on 2012/09/13 01:19
Change comment: checking out of stash. very cool!

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.kieran
1 +XWiki.kiddyr
Content
... ... @@ -171,3 +171,19 @@
171 171  git reset --hard
172 172  
173 173  {{/code}}
174 +
175 +=== Stash to Clean and Checkout from Stash to Work ===
176 +
177 +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?
178 +
179 +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:
180 +
181 +{{code}}
182 +
183 +git checkout stash@{0} -- file1.java
184 +git checkout stash@{0} -- file3.java
185 +
186 +{{/code}}
187 +
188 +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!
189 +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.