When VSCode pulls the code, it prompts: Before checking out, please clean up the repository working tree (for your own study and records)

When VSCode pulls the code, it prompts: Please clean the repository working tree before checking out [^1]

1. Problem description 1

When you modify the code of the git project in VSCode, if someone else modifies the same file code at the same time as you, it will cause a writing conflict. If you pull the code at this time, a conflict prompt will be given: Before checking out , please clean the repository working tree.

2. Solution

1. How to save local modifications

Since it is a code conflict, only the following three lines of code are enough (create a new one in VSCode or open a terminal and enter it in the terminal):

//先将本地修改存储起来
git stash 
//拉取远程
git pull
//还原暂存内容
git stash pop 

Pull can be replaced by clicking "Pull" in git (PS: I suspect that both stash and stash pop can directly click a button, but I haven't found it, and it is not troublesome to enter anyway)

2. Give up the method of local modification

Because it conflicts with code submitted by others, you can directly discard local changes by using the following two lines of code;

git reset --hard
git pull

  1. Article reference: https://blog.csdn.net/m0_38115669/article/details/108564602 ↩︎

Guess you like

Origin blog.csdn.net/weixin_47278656/article/details/129950881