scenario

Git stash is a common operation when we use Git. For example, we are fixing a bug in branch A and change some files. But there is an urgent bug in branch B and we need to switch to branch B to fix it. Git Checkout branch B will commit the modified file first. But what if you don’t want to commit because the bug on branch A isn’t completely fixed, so git Stash comes out

Git Stash basic usage

  1. Check out the added stash contents, the Git Stash list
  2. Add the modified content to the stash, git stash; If you need to include new files, you can add the -u parameter, git stash -u
  3. Git stash apply 0(the first stash record) to restore the first stash to the workspace (the stash record is saved); If you don’t need to save it in stash after recovery, you can use git stash pop 0(0 is the first stash record).
  4. Git Stash clear

Git Stash Clear after recovery

If we store some files that have been modified with git Stash and then clear them with git Stash, can we restore them?

And the answer is yes

Git FSCK

steps

  1. Git FSCK –lost-found git FSCK –lost-found Git FSCK –lost-found Git FSCK –lost-found Git FSCK –lost-found git FSCK –lost-found git FSCK –lost-found git FSCK –lost-found git FSCK –lost-found
  2. Git show commitId check the changes one by one and find the commitId we need to restore
  3. Git stash apply commitId