Locally modified files, after using git stash to temporarily store, the temporary storage area is accidentally emptied, and the previously temporarily stored files are retrieved

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

  1. git log --graph --oneline --decorate $( git fsck --no-reflog | awk ‘/dangling commit/ {print $3}’ )

  2. git stash apply number

the case

Operate in the above sequence, enter the command and press Enter.

  1. 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:
insert image description here
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

  1. input command

git stash apply b20ea19

But after pressing Enter, an error is reported, and you can see the picture below:
insert image description here
Use git stash list to view the contents of the temporary storage area. Found nothing after git stash list.
insert image description here
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

  1. clear staging area

git stash clear

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

Guess you like

Origin blog.csdn.net/blqzj214817/article/details/129046453