How to delete a stash created with git stash create?

前端 未结 9 982
失恋的感觉
失恋的感觉 2020-12-04 04:28

Git stash seems to do a lot of what I want, except that it is a little hard to script, as the if you have no changes, then git stash; git stash pop will do some

相关标签:
9条回答
  • 2020-12-04 04:57
    git stash           // create stash,
    git stash push -m "message" // create stash with msg,
    git stash apply         // to apply stash,
    git stash apply indexno // to apply  specific stash, 
    git stash list          //list stash,
    git stash drop indexno      //to delete stash,
    git stash pop indexno,
    git stash pop = stash drop + stash apply
    git stash clear         //clear all your local stashed code
    
    0 讨论(0)
  • 2020-12-04 05:01

    From git doc: http://git-scm.com/docs/git-stash

    drop [-q|--quiet] []

    Remove a single stashed state from the stash list. When no is given, it removes the latest one. i.e. stash@{0}, otherwise must be a valid stash log reference of the form stash@{}.

    example:

    git stash drop stash@{5}
    

    This would delete the stash entry 5. To see all the list of stashes:

    git stash list
    
    0 讨论(0)
  • 2020-12-04 05:01

    Git stash clear will clear complete stash,

    cmd: git stash clear

    If you want to delete a particular stash with a stash index, you can use the drop.

    cmd: git stash drop 4

    (4 is stash id or stash index)

    0 讨论(0)
  • 2020-12-04 05:06

    If you are 100% sure that you have just one stash or you want to delete all stashes (make a git stash list to be 107% sure), you can do a:

    git stash clear
    

    ..and forget about them (it deletes all stashes).

    Note: Added this answer for those who ended up here looking for a way to clear them all (like me).

    0 讨论(0)
  • 2020-12-04 05:16

    To delete a normal stash created with git stash , you want git stash drop or git stash drop stash@{n}. See below for more details.


    You don't need to delete a stash created with git stash create. From the docs:

    Create a stash entry (which is a regular commit object) and return its object name, without storing it anywhere in the ref namespace. This is intended to be useful for scripts. It is probably not the command you want to use; see "save" above.

    Since nothing references the stash commit, it will get garbage collected eventually.


    A stash created with git stash or git stash save is saved to refs/stash, and can be deleted with git stash drop. As with all Git objects, the actual stash contents aren't deleted from your computer until a gc prunes those objects after they expire (default is 2 weeks later).

    Older stashes are saved in the refs/stash reflog (try cat .git/logs/refs/stash), and can be deleted with git stash drop stash@{n}, where n is the number shown by git stash list.

    0 讨论(0)
  • 2020-12-04 05:17

    You should be using

    git stash save
    

    and not

    git stash create
    

    because this creates a stash (which is a regular commit object) and return its object name, without storing it anywhere in the ref namespace. Hence won't be accessible with stash apply.

    Use git stash save "some comment" is used when you have unstaged changes you wanna replicate/move onto another branch

    Use git stash apply stash@{0} (assuming your saved stash index is 0) when you want your saved(stashed) changes to reflect on your current branch

    you can always use git stash list to check all you stash indexes

    and use git stash drop stash@{0} (assuming your saved stash index is 0 and you wanna delete it) to delete a particular stash.

    0 讨论(0)
提交回复
热议问题