A git pull error, error: Your local changes to the following files would be overwritten by merge, occurs because changes to the local branch are not saved when git pulls.
There are two general solutions. There is also a special case, that is, the change of permissions such as file reading and writing.
Method 1: discard local changes
If the local modification is not important, you can directly discard the local modification:
# Discard all local uncommitted changes
git checkout .
Some local files are newly added but not Add
, the status in git status
is untrack
, and they need to be deleted through git clean
# First check what files will be deleted
git clean -nxdf
# Make sure the files that will be deleted are correct, then execute the delete
git clean -xdf
# You can also delete files one by one, for example, delete file xxx
git clean -f xxx
Or
Direct execution:
git reset --hard
git pull
Note: discarding local files is a dangerous operation and must be considered before deleting.
Method 2: temporarily store to the stack area
If local modifications are important. If it needs to be used later, the current modification can be temporarily stored in the stack area:
# Staging to the stack area
git stash
# View stash contents
git stash list
To use local modification, apply the stash
content to the local branch:
git stash pop
The contents in stash
are popped up. If multiple temporary contents are saved, the pop-up order is first in and last out (stack).
If you do not want to pop up the content, but still apply the stash
content to the local branch:
git stash apply
In this way, the contents in stash
will not be ejected.
In addition, you can manually delete the content in stash
# Delete the contents of a specified stash, the name of which can be obtained from the git stash list
git stash drop xxx
# Delete all stash content
git stash clear
Generally:
git stash
git commit
git stash pop
Git stash: back up the contents of the current workspace, read the relevant contents from the latest submission, and ensure that the workspace is consistent with the last submission. At the same time, save the current workspace content to the GIT stack
git stash Pop: read the last saved content from the GIT stack and recover the relevant content of the workspace. Since there may be multiple stash contents, it is managed by stack. Pop will read the contents from the latest stash and recover them
git stack list: displays all backups in the GIT stack. You can use this list to decide where to recover
git stack clear: clear the GIT stack. At this time, graphical tools such as gitg will be used to find out which nodes of the original stash have disappeared.
Note: merge after using git stash
to temporarily store content, and then git stash pop
, branch conflict may be reported. At this time, you can create a new branch locally and recover the stash content on the new branch.
exceptional case:
Git prompts that the file has been modified, but the actual content has not been modified. The reason is that all git libraries will ignore the change of FileMode.
Git diff prompts the change of FileMode, as follows:
git diff xxx
diff --git a/xxx b/xxx
old mode 100755
new mode 100644
Solution:
#Terminal Execution
git config --add core.filemode false
Read More:
- Git Pull error: Your local changes to the following files would be overwritten by merge:
- Git Pull Error:The following untracked working tree files would be overwritten by merge
- git error: The following untracked working tree files would be overwritten by checkout
- Git: How to Solve Error: Please commit your changes or stash them before you merge.
- [Solved] Git Error: fatal: refusing to merge unrelated histories
- Git Error: refusing to merge unrelated histories [How to Solve]
- [Solved] Git Error: fatal: refusing to merge unrelated histories
- Git under Windows reports an error: warning: LF will be replaced by CRLF in ××××.××
- [Solved] Doris StreamLoad Error: load by MERGE or DELETE need to upgrade table to support batch delete
- Local repository upload to remote repository error: failed to push some refs to ‘https://hub.fastgit.org/zhizhangxuezhang/ui-test.git‘
- git submodule add Error: SSL certificate problem unable to get local issuer certificate
- Appcompatactivity Error: WARNING: Local History will be also cleared.
- [Solved] swiper Error: The requested module ‘react’ is expected to be of type CommonJS, which does not support named exports. CommonJS modules can be imported by importing the default export
- [Solved] Git pull error: cannot pull with rebase: Your index contains uncommitted changes.
- [Solved] Toad Set Error: The following files specified on the Executables tab could not be found:TNS Ping
- [Solved] CMake error: error in configuration process, project files may be invalid
- How to Fix Error Cannot find command ‘git‘ – do you have ‘git‘ installed and in your PATH?
- This limit can be set by changing the [search.max_open_scroll_context] setting
- Solution of socket write error caused by pressing F5 to refresh page by ehcache user
- Git pull and Git pull origin master Warning: Pulling without specifying how to reconcile divergent branches