git-stash vs. git-branch

前端 未结 4 1886
一整个雨季
一整个雨季 2021-01-29 19:03

In a previous Git question, Daniel Benamy was talking about a workflow in Git:

I was working on master and committed some stuff and then decided I wanted

4条回答
  •  猫巷女王i
    2021-01-29 19:22

    When you restore your stash, your changes are reapplied and you continue working on your code.

    To stash your current changes

    $ git stash save 
    Saved "WIP on master: e71813e..."
    

    You can also have more than one stash. The stash works like a stack. Every time you save a new stash, it's put on top of the stack.

    $ git stash list
    stash@{0}: WIP on master: e71813e..."
    

    Note the stash@{0} part? That's your stash ID. You'll need it to restore it later on. Let's do that right now. The stash ID changes with every stash you make. stash@{0} refers to the last stash you made.

    To apply a stash

    $ git stash apply stash@{0}
    

    You may notice the stash is still there after you have applied it. You can drop it if you don't need it any more.

    $ git stash drop stash@{0}
    

    Or, because the stash acts like a stack, you can pop off the last stash you saved:

    $ git stash pop
    

    If you want to wipe all your stashes away, run the 'clear' command:

    $ git stash clear
    

    It may very well be that you don't use stashes that often. If you just want to quickly stash your changes to restore them later, you can leave out the stash ID.

    $ git stash
    ...
    $ git stash pop
    

    Feel free to experiment with the stash before using it on some really important work.

    I also have a more in-depth version of this posted on my blog.

提交回复
热议问题