Skip to content

Instantly share code, notes, and snippets.

@Dunstonhary
Forked from joseluisq/stash_dropped.md
Created July 16, 2024 11:38
Show Gist options
  • Save Dunstonhary/d5e573761e2f1326edf599898eb6349a to your computer and use it in GitHub Desktop.
Save Dunstonhary/d5e573761e2f1326edf599898eb6349a to your computer and use it in GitHub Desktop.

Revisions

  1. @joseluisq joseluisq revised this gist Nov 30, 2020. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions stash_dropped.md
    Original file line number Diff line number Diff line change
    @@ -20,14 +20,14 @@ _**Note:** The commit message will only be in this form (starting with "WIP on")

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

    ## 3. If you stash commit is not listed or you don't find it (optional)
    ## 3. If your stash commit is not listed or you don't find it (optional)

    If you stash was already applied but you don't see it, for example after resolving a conflict or reset.
    If your stash was already applied but you don't see it, for example after resolving a conflict or reset.
    Follow these steps:

    - Run `git fsck --no-reflog | awk '/dangling commit/ {print $3}'`
    - Pick a stash commit hash and use `git show COMMIT_HASH` in order to explore the stash commit diff of your changes.
    - Identify the commit of your stash changes and just apply it using `git stash apply COMMIT_HASH`
    - Pick a stash commit hash and use `git show COMMIT_HASH` in order to examine the stash commit diff of your changes.
    - After found your changes just use the corresponding commit of your stash changes and then just apply it using `git stash apply COMMIT_HASH`.

    ## Bonus

  2. @joseluisq joseluisq revised this gist Oct 21, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion stash_dropped.md
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ _**Note:** The commit message will only be in this form (starting with "WIP on")

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

    ## 3. If you stash commit gets not listed or you don't find it (optional)
    ## 3. If you stash commit is not listed or you don't find it (optional)

    If you stash was already applied but you don't see it, for example after resolving a conflict or reset.
    Follow these steps:
  3. @joseluisq joseluisq revised this gist Oct 21, 2020. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions stash_dropped.md
    Original file line number Diff line number Diff line change
    @@ -20,6 +20,15 @@ _**Note:** The commit message will only be in this form (starting with "WIP on")

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

    ## 3. If you stash commit gets not listed or you don't find it (optional)

    If you stash was already applied but you don't see it, for example after resolving a conflict or reset.
    Follow these steps:

    - Run `git fsck --no-reflog | awk '/dangling commit/ {print $3}'`
    - Pick a stash commit hash and use `git show COMMIT_HASH` in order to explore the stash commit diff of your changes.
    - Identify the commit of your stash changes and just apply it using `git stash apply COMMIT_HASH`

    ## Bonus

    If you are [Fish shell](https://fishshell.com/) user, you can take a look at [GitNow](https://github.com/joseluisq/gitnow) which is a tool to perform faster Git operations and that can also stash your changes for you.
  4. @joseluisq joseluisq revised this gist Jul 22, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion stash_dropped.md
    Original file line number Diff line number Diff line change
    @@ -22,4 +22,4 @@ __Source:__ View the complete answer at https://stackoverflow.com/a/91795/251059

    ## Bonus

    If you are [Fish shell](https://fishshell.com/) user, you can take a look [GitNow](https://github.com/joseluisq/gitnow) which is a tool to perform faster Git operations and that can also stash your changes for you.
    If you are [Fish shell](https://fishshell.com/) user, you can take a look at [GitNow](https://github.com/joseluisq/gitnow) which is a tool to perform faster Git operations and that can also stash your changes for you.
  5. @joseluisq joseluisq revised this gist Jul 22, 2020. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions stash_dropped.md
    Original file line number Diff line number Diff line change
    @@ -8,14 +8,18 @@ git log --graph --oneline --decorate ( git fsck --no-reflog | awk '/dangling com

    _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._

    __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.
    __bash/sh shell users:__ Version above is for [Fish shell](https://fishshell.com/), 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
    git stash apply YOUR_WIP_COMMIT_HASH_HERE
    ```

    _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._
    _**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

    ## Bonus

    If you are [Fish shell](https://fishshell.com/) user, you can take a look [GitNow](https://github.com/joseluisq/gitnow) which is a tool to perform faster Git operations and that can also stash your changes for you.
  6. @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
  7. @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
  8. @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