当我运行git pull
时,我收到以下错误:
Updating 745a0be..5b50b37
error: Your local changes to the following files would be overwritten by merge:
src/main/config/runtime/common/app/log4j2.json
src/main/config/runtime/dev/app/application.properties
Please commit your changes or stash them before you merge.
Aborting
到目前为止,我查看的所有答案都涉及使用git stash
,git checkout -- .
或git reset --hard HEAD
删除这些文件。但是,在这种情况下,这些未暂停的更改是由于repo的.gitattributes
文件导致的新行规范化:
* text=auto
正在运行git stash
,git checkout -- .
或git reset --hard HEAD
无法清除我的回购中的任何未暂停的更改。
git stash
:
$ git stash
warning: CRLF will be replaced by LF in src/main/config/runtime/common/app/log4j2.json.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in src/main/config/runtime/dev/app/application.properties.
The file will have its original line endings in your working directory.
Saved working directory and index state WIP on master: 745a0be Merge pull request #37 in AS/openshift-example from json-validate to dmz
$ git status
On branch master
Your branch is behind 'origin/master' by 30 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: src/main/config/runtime/common/app/log4j2.json
modified: src/main/config/runtime/dev/app/application.properties
no changes added to commit (use "git add" and/or "git commit -a")
git checkout -- .
:
$ git checkout -- .
$ git status
On branch master
Your branch is behind 'origin/master' by 30 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: src/main/config/runtime/common/app/log4j2.json
modified: src/main/config/runtime/dev/app/application.properties
no changes added to commit (use "git add" and/or "git commit -a")
git reset --hard HEAD
:
$ git reset --hard HEAD
HEAD is now at 745a0be Merge pull request #37 in AS/openshift-example from json-validate to dmz
$ git status
On branch master
Your branch is behind 'origin/master' by 30 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: src/main/config/runtime/common/app/log4j2.json
modified: src/main/config/runtime/dev/app/application.properties
no changes added to commit (use "git add" and/or "git commit -a")
如何告诉git pull
覆盖任何本地更改?
更新:
我尝试了git pull --force
并且出现了同样的错误:
$ git pull --force
Updating 745a0be..5b50b37
error: Your local changes to the following files would be overwritten by merge:
src/main/config/runtime/common/app/log4j2.json
src/main/config/runtime/dev/app/application.properties
Please commit your changes or stash them before you merge.
Aborting
答案 0 :(得分:0)
没有“强迫拉”这样的事情。 ( --force
标记为git fetch
,而git pull
会将--force
传递给git fetch
,但这对此无效情况)。
除了修复实际问题之外,还有一种方法可以解决此问题,现在不使用git pull
。而是首先运行git fetch
,然后运行git reset --hard
:
git fetch origin
git reset --hard origin/master
(假设您在master
上,并且您不希望根据* text=auto
行保留您/您的Git所做的本地更改。别)。如果控制您的origin
回购的任何人在此修复了根本问题 - 是否要避免将*.json
和*.properties
视为文本,或者清除这些文件的已提交内容,或者两者兼而有之 - 你会同时拿起修复程序。如果没有,您可以要求他们修复它,或者之后向他们提交修复程序。