Tag Archives: Git conflict Error

Git Conflict Error: commit your changes or stash them before you can merge. [How to Solve]

To update the code with git pull, we encountered the following problems:

error:Yourlocalchangestothefollowingfileswouldbeoverwrittenbymerge :

xxx/xxx/xxx.java

Please,commityourchangesorstashthembeforeyoucanmerge.

Aborting

the tips are very friendly, and the answers from netizens can help me solve the problem directly

1.stash

Usually, if you encounter this problem, you can directly commit your modification; But I don’t want to do that this time

See how git stash does it

git stash
git pull
git stash pop

Next, diff this file to see the situation of automatic merging, and make corresponding changes

Git stash: back up the content of the current workspace, read the relevant content from the latest submission, and make the workspace consistent with the content submitted last time. At the same time, save the current workspace content to git stack
git stash Pop: read the last saved content from git stack to recover the related content of the workspace. Since there may be multiple stash contents, the stack is used to manage them. Pop will read the contents from the latest stash and recover them
git stash list: displays all the backups in Git stack, which can be used to decide where to recover from
git stash clear: clear git stack. At this point, using gitg and other graphical tools, you will find that the original stash nodes have disappeared

2. Abandon local modification and directly cover it

git reset --hard
git pull

[Solved] Git conflict Error: commit your changes or stash them before you can merge

Git conflict: commit your changes or stash them before you can merge

When updating the code with git pull, we encountered the following problems:

error: Your local changes to the following files would be overwritten by merge:
*********************************************************
Please, commit your changes or stash them before you can merge.
Aborting

The reason for this problem is that other people have modified xxx.php and submitted it to the version library, and you have also modified xxx.php locally. At this time, if you do git pull, there will be a conflict. The solution is very clear in the above prompt

1. Retain local modification

1) Direct commit local modification — this method is not generally used

2) Through git stash — usually this way

git stash
git pull
git stash pop

Restore the work area to the last submitted content through git stash, and back up the local changes at the same time. After git pull is completed, execute git stash pop to apply the previous local changes to the current work area

Git stash: back up the content of the current workspace, read the relevant content from the latest submission, and make the workspace consistent with the content submitted last time. At the same time, save the current workspace content to git stack

Git stash Pop: read the last saved content from git stack and recover the related content of workspace. Since there may be multiple stash contents, the stack is used to manage them. Pop will read the contents from the latest stash and recover them

Git stash list: displays all the backups in Git stack. You can use this list to decide where to recover from

Git stash clear: clear git stack. At this point, using gitg and other graphical tools, you will find that the original stash nodes have disappeared

2. Discard the local modification – this method discards the local modification and cannot be retrieved

git reset --hardgit pull< br>& lt; br>& lt; br>& lt; br>& lt; br>& lt; br>