Please commit your changes or stash them before you merge
- When updating code with Git pull, you encountered the following problem:
error: Your local changes to the following files would be overwritten by merge:
xxx/xxx/xxx.php
Please, commit your changes or stash them before you can merge.
Aborting
Copy the code
- The reason for this problem is that someone else has modified xxx.php and submitted it to the repository, and you have modified xxx.php locally,
When you do git pull, the conflict will occur. The solution is clear in the tips above.
1. Retain local amendments
1) Commit local changes to —-
2) Through git stash —- this method is usually used
git stash
git pull
git stash pop
Copy the code
After restoring your workspace to the last commit with your git Stash stash and backing up your local changes, git pull is ready. After git pull is complete, execute git Stash pop to apply your local changes to the current workspace.
Git Stash: Backs up the contents of the current workspace, reading from the last commit and keeping the workspace consistent with the last commit. At the same time, save the current workspace contents to Git stack.
Git stash pop: Restores the workspace by reading the most recently saved contents from the Git stack. Since there can be multiple Stash contents, a stack is used to manage the contents, and pop reads from the nearest Stash and restores the contents.
Git Stash List: Displays all backups in your Git stack. You can use this list to decide where to restore from.
Git Stash clear: Clears the Git stack. At this point, graphic tools such as GITg can be used to find out which stash nodes have disappeared
—- This method will discard the locally modified code, and cannot be retrieved. It is not recommended to use this method.
git reset --hard
git pull
Copy the code
Git command collation
Blog Source: Blog of rainy Night