overview
question
When using git daily, use git stash to temporarily store the local modifications. After using git pull to pull the code, use git stash clear to delete the content temporarily stored in git stash. This article describes how to restore the temporary storage area code dropped by git stash clear.
Solution
execute command
-
git log --graph --oneline --decorate $( git fsck --no-reflog | awk ‘/dangling commit/ {print $3}’ )
-
git stash apply number
the case
Operate in the above sequence, enter the command and press Enter.
- input command
git log --graph --oneline --decorate $( git fsck --no-reflog | awk ‘/dangling commit/ {print $3}’ )
Copy the above command directly, and then press Enter, no need to make any changes.
After execution, the following list will appear:
in the above list, find the description of the line that may have been modified by you, and copy the previous yellow number.
For example: when I was temporarily storing "adding the signal slot binding and function of the centerline list that needs to be displayed", the modification I made at that time may exist. I have forgotten it. For the sake of safety, I choose the next line described in this line. "Optimize plaque", so my command is:
git stash apply b20ea19
- input command
git stash apply b20ea19
But after pressing Enter, an error is reported, and you can see the picture below:
Use git stash list to view the contents of the temporary storage area. Found nothing after git stash list.
Therefore, use the command git stash to temporarily store.The reason why it is temporarily stored here is that the reason for the error report after executing git stash apply b20ea19 is due to the two conflicting files mentioned in the error report (the previously conflicting files are no longer conflicting).
After temporary storage, then execute
git stash apply b20ea19
It can be seen that after execution, no error is reported. And found the files in the temporary storage area that were deleted before.
additional gain
- clear staging area
git stash clear
- Staging modified files
git stash
3. Pull the most recent staging
git stash pop
4. Restore the cleared temporary storage area files
git log --graph --oneline --decorate $( git fsck --no-reflog | awk ‘/dangling commit/ {print $3}’ )
git stash apply 编号
The number here is the number to locate the file that has not been deleted before according to your own text description after pressing Enter on the first line of command.