error: Your local changes to the following files would be overwritten by merge

Other members of the team have modified a file and submitted it to the library. You have modified the local file before pulling. When you have finished modifying the code and then pulling, the following error will be reported:

error: Your local changes to the following files would be overwritten by merge

Depending on whether you want to save local modifications, there are two solutions:

1.Changes reserved

git stash #Archive changes
git pull origin master
git stash pop #Revert the changes

git stash: Back up the content of the current workspace, read the relevant content from the most recent commit, and ensure that the workspace is consistent with the content of the last commit. At the same time, save the current workspace content to the Git stack
git pull: pull the current branch code on the server
git stash pop: Read the last saved content from the Git stack and restore the workspace-related content. At the same time, the user may perform multiple stash operations, and it is necessary to ensure that the stash is retrieved first, so it is managed by stack (first-in, last-out); pop takes the contents of the top of the stack and restores it
git stash list: Displays all backups in the Git stack, you can use this list to decide where to restore from.
git stash clear: clears the Git stack

2.Abandoned Modifications

The core idea is to roll back the version, the specific commands are as follows

git reset --hard 
git pull origin master

Note: The second one is not recommended. Unless you’re reassured that you don’t need local changes.

Leave a Reply

Your email address will not be published. Required fields are marked *