| | 262 | |
| | 263 | '''git''' provides a very useful feature where one can save the current state of all working files and return to the committed state. For example, while working some files, a developer may need to update some other files to fix a bug. The already changed files are not ready to be committed into the repository, but they should not be discarded either. Using the '''stash''' command, the developer can |
| | 264 | - save the current changes, |
| | 265 | - return to the committed state, |
| | 266 | - make and commit bug fix changes, |
| | 267 | - restore the saved changes, |
| | 268 | - pull back the bug fix changes, and |
| | 269 | - continue development. |
| | 270 | |
| | 271 | {{{#!html |
| | 272 | <pre style="margin-left:20px; margin-right:20px; border:solid 1px; padding:3px; background:white;"> |
| | 273 | <b style="color:#2a2;">[loft - /e/chimera2]$ pwd</b> |
| | 274 | /e/chimera2 |
| | 275 | <b style="color:#2a2;">[loft - /e/chimera2]$ git status</b> |
| | 276 | # On branch develop |
| | 277 | # Changes not staged for commit: |
| | 278 | # (use "git add <file>..." to update what will be committed) |
| | 279 | # (use "git checkout -- <file>..." to discard changes in working directory) |
| | 280 | # |
| | 281 | # modified: example |
| | 282 | # |
| | 283 | no changes added to commit (use "git add" and/or "git commit -a") |
| | 284 | <b style="color:#2a2;">[loft - /e/chimera2]$ echo "some changes" > example</b> |
| | 285 | <b style="color:#2a2;">[loft - /e/chimera2]$ git status</b> |
| | 286 | # On branch develop |
| | 287 | # Changes not staged for commit: |
| | 288 | # (use "git add <file>..." to update what will be committed) |
| | 289 | # (use "git checkout -- <file>..." to discard changes in working directory) |
| | 290 | # |
| | 291 | # modified: example |
| | 292 | # |
| | 293 | no changes added to commit (use "git add" and/or "git commit -a") |
| | 294 | <b style="color:#2a2;">[loft - /e/chimera2]$ git stash</b> |
| | 295 | Saved working directory and index state WIP on develop: fb5b90a Merge branch 'feature/my_new_feature' into develop |
| | 296 | HEAD is now at fb5b90a Merge branch 'feature/my_new_feature' into develop |
| | 297 | <b style="color:#2a2;">[loft - /e/chimera2]$ cat example</b> |
| | 298 | finished product |
| | 299 | <br/><i><b style="color:#d22;">Here, the developer can make and commit updates without including the earlier changes.</b></i><br/> |
| | 300 | <b style="color:#2a2;">[loft - /e/chimera2]$ git stash list</b> |
| | 301 | stash@{0}: WIP on develop: fb5b90a Merge branch 'feature/my_new_feature' into develop |
| | 302 | <b style="color:#2a2;">[loft - /e/chimera2]$ git stash pop</b> |
| | 303 | # On branch develop |
| | 304 | # Changes not staged for commit: |
| | 305 | # (use "git add <file>..." to update what will be committed) |
| | 306 | # (use "git checkout -- <file>..." to discard changes in working directory) |
| | 307 | # |
| | 308 | # modified: example |
| | 309 | # |
| | 310 | no changes added to commit (use "git add" and/or "git commit -a") |
| | 311 | Dropped refs/stash@{0} (9c7ea9292cd81bd1f4d2606dbab129e3cdd5c0d9) |
| | 312 | <b style="color:#2a2;">[loft - /e/chimera2]$ cat example</b> |
| | 313 | some changes |
| | 314 | <b style="color:#2a2;">[loft - /e/chimera2]$ git pull</b> |
| | 315 | Already up-to-date. |
| | 316 | </pre> |
| | 317 | }}} |