Skip to content

Instantly share code, notes, and snippets.

@ArturJS
Forked from joseluisq/stash_dropped.md
Created February 19, 2020 08:43
Show Gist options
  • Save ArturJS/7267b29f9d0371db2a71750997b79b62 to your computer and use it in GitHub Desktop.
Save ArturJS/7267b29f9d0371db2a71750997b79b62 to your computer and use it in GitHub Desktop.

Revisions

  1. @joseluisq joseluisq revised this gist Oct 11, 2019. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions stash_dropped.md
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,16 @@
    # How to recover a dropped stash in Git?

    __1. Find the stash commits:__
    ## 1. Find the stash commits

    ```sh
    git log --graph --oneline --decorate ( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )
    ```

    _This will show you all the commits at the tips of your commit graph which are no longer referenced from any branch or tag – every lost commit, including every stash commit you’ve ever created, will be somewhere in that graph._

    __2. Once you know the hash of the commit you want, you can apply it as a stash:__
    __bash/sh shell users:__ Version above is for Fish shell, so if you are bash/sh user just add a `$` sign before to the left parenthesis.

    ## 2. Once you know the hash of the commit you want, you can apply it as a stash

    ```sh
    git stash apply YOUR_WIP_COMMIT_HASH
  2. @joseluisq joseluisq revised this gist Feb 2, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions stash_dropped.md
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    # How to recover a dropped stash in Git?

    1. Find the stash commits:
    __1. Find the stash commits:__

    ```sh
    git log --graph --oneline --decorate ( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )
    ```

    _This will show you all the commits at the tips of your commit graph which are no longer referenced from any branch or tag – every lost commit, including every stash commit you’ve ever created, will be somewhere in that graph._

    2. Once you know the hash of the commit you want, you can apply it as a stash:
    __2. Once you know the hash of the commit you want, you can apply it as a stash:__

    ```sh
    git stash apply YOUR_WIP_COMMIT_HASH
  3. @joseluisq joseluisq created this gist Feb 2, 2018.
    19 changes: 19 additions & 0 deletions stash_dropped.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    # How to recover a dropped stash in Git?

    1. Find the stash commits:

    ```sh
    git log --graph --oneline --decorate ( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )
    ```

    _This will show you all the commits at the tips of your commit graph which are no longer referenced from any branch or tag – every lost commit, including every stash commit you’ve ever created, will be somewhere in that graph._

    2. Once you know the hash of the commit you want, you can apply it as a stash:

    ```sh
    git stash apply YOUR_WIP_COMMIT_HASH
    ```

    _Note: The commit message will only be in this form (starting with "WIP on") if you did not supply a message when you did git stash._

    __Source:__ View the complete answer at https://stackoverflow.com/a/91795/2510591