Git stash

Often, when you’ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else. The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later. The answer to this issue is the git stash command.
Stashing takes the dirty state of your working directory — that is, your modified tracked files and staged changes — and saves it on a stack of unfinished changes that you can reapply at any time.

Stashing Your Work

$ git status
On branch optimize_add_surround_audio_test
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   app/src/androidTest/java/com/XXX/XXX/MainTest.java

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        JenkinsRun.sh.bak

no changes added to commit (use "git add" and/or "git commit -a")
$ git stash
Saved working directory and index state WIP on optimize_add_surround_audio_test: 5509c63 Merge branch 'dev' of XXX/XXX into master
$ git status
On branch optimize_add_surround_audio_test
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        JenkinsRun.sh.bak

nothing added to commit but untracked files present (use "git add" to track)

Then it is safe to switch to other branches without committing or losing anything.

$ git stash list
stash@{0}: WIP on optimize_add_surround_audio_test: 5509c63 Merge branch 'dev' of XXX/XXX into master
stash@{1}: WIP on optimize_failing_screenshot_capture: a72194b add suite logger
$ git stash show stash@{1}
 .../com/mrvl/netflixwithopencv02/MainTest.java     | 66 ++++++++++++++--------
 .../java/com/mrvl/netflixwithopencv02/Methods.java | 47 ++++++++-------
 2 files changed, 69 insertions(+), 44 deletions(-)
$ git stash drop stash@{1}
Dropped stash@{1} (fdee692a43f37fc38e4fd6bfe5587eec7696b7ee)
$ git stash list
stash@{0}: WIP on optimize_add_surround_audio_test: 5509c63 Merge branch 'dev' of XXX/XXX into master
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,452评论 0 10
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,959评论 0 23
  • 解开席草,剥开粽叶,咬上一口,满满糯糯的感觉,又到了吃粽子的时候了。 对于粽子,因为喜爱,总是心存着好多记忆。 那...
    闲着也是闲着lily阅读 515评论 1 0
  • 有人说 青春是一人的兵荒马乱 有多少人 都是草草收场 01 一到周末,整个宿舍就剩下冬瓜一个人了。 其他人,都处对...
    沫子真阅读 537评论 0 1
  • 2018.2.14 这次依旧没有准时在2.12发布,我的错,竟然捧着手机就在被子里睡着了! 不想说早上6:30出门...
    聆寻阅读 166评论 0 0