Remember the rescue process after the local code is lost due to direct pull of Git without Commit

It's the first time I've encountered this kind of problem, I'm a little nervous...

Well, without further ado, IDEA or AndroidStudio enters Git Uncommiteed Changes -> Unstash Changes:

In the pop-up Unstash Changes dialog box, click View to view the code. If the code is a local lost code, congratulations, you can continue to play happily again. But be careful not to click the Drop and Clear buttons casually.

At this time we have three ways to restore our code: git stash apply, git stash pop and git stash branch.

The difference between the three reference: git stash command practical guide | Linux China

The author chose git stash branch, because creating a branch can avoid merge conflicts, and then consider merging branches after the code is restored.

Fill in the branch name in the dialog and the button will change from Apply to Branch. Of course, we can also use the command line to execute.

 Fill in the new branch name and click the Branch button.

After waiting for completion, it will automatically switch to our newly created branch.

Check the code again, it has been successfully restored, Bingo ! Good night, sweet dreams.

To sum up, if git pull causes the loss of local code, you can first check whether there is a temporary storage in git stash, and if so, you can be lucky enough to restore it. If not, then take a look at the recycle bin and Local History, if not, then there is a high probability that it will be cold, so let’s mourn. The lesson of blood and tears tells us how important it is to have a good habit of using git. Remember to commit first in the future.

Finally, I recommend another article to review git stash: How to use git stash and git branch

Guess you like

Origin blog.csdn.net/xiangang12202/article/details/129889951