When using git pull code, you often encounter conflicts, and the following message is prompted:
error: Your local changes to 'c/environ.c' would be overwritten by merge. Aborting.
Please, commit your changes or stash them before you can merge.
This means that the updated content conflicts with the locally modified content. Submit your changes first or temporarily store the local modifications first.
The processing method is very simple, mainly using the git stash command, which is divided into the following steps.
1. First store the local modifications
$ git stash
In this way, all local modifications will be temporarily stored. You can use git stash list to see the saved information:
git stash temporary changes
git stash temporary changes
stash@{0} is the mark just saved.
2. Pull content
After temporarily saving local modifications, you can pull.
$ git pull
3. Restore the temporary content
$ git stash pop stash@{0}
The system prompts a message similar to the following:
Auto-merging c/environ.c
CONFLICT (content): Merge conflict in c/environ.c
means that the system automatically merges the modified content, but there are conflicts and the conflicts need to be resolved.
4. Resolve the conflicting part in the file
Open the conflicting file and you will see content similar to the following:
git conflict content
git conflict content
The content between Updated upstream and ===== It is the pulled content, and the content between ==== and stashed changes is the locally modified content. In this case, git doesn't know which line of content is needed, so you have to determine the required content by yourself.
After the solution is completed, you can submit it normally.