GIT pulling code local modification conflicts with remote warehouse code

Code path: local modification -> personal remote warehouse -> public remote warehouse

The cause of this problem is that the local code has been modified, but there is no git pull to update it in advance. At this time, when using git pull to pull the remote warehouse code to update, it will report the error of conflict between the local code and the remote warehouse code: "Your local changes to the following files would be overwritten by merge: ...".

When encountering this problem, if you do not want to discard the local modification code, but also want to pull the remote warehouse code for update, you must solve the problem of code conflict.

Solution ideas and steps:

(1) Back up local code: git stash command, which will back up all modified files to the stack area, but other files do not conflict and do not need to be backed up. You can use the following method to back up only a certain file (it is easy to go wrong after verification, Refer to the LOG_cmd.xml mentioned later):

a. All modified files git add

b. git reset HEAD withdraws the files that need to be backed up

 c. git stash --keep-index, then only files without git add will be backed up. But the xxx.xml file stash reports an error. It stands to reason that the file has been git added and should not be stashed.

 git status view:

(2) git pull pull code

git status: 

At this time, the updated code does not conflict with what I modified, so the git pull can be successful.

(3) git stash pop restores the backup from the stack

After execution, the original file will be in modified.

(4) xxx.xml that handles exceptions 

 

git status view

At this time, xxx.xml becomes an unmodified file.

Re-modify xxx.xml submission.

Note: After git stash pop restores the backup from the stack, you may encounter conflicts. If there are conflicts, you must resolve the conflicts.

Guess you like

Origin blog.csdn.net/hhhlizhao/article/details/128891228