如何让git覆盖未发现的本地更改?

时间:2015-12-21 16:09:27

标签: git

目前git陷入了循环。由于本地更改,它无法合并。我无法存储本地更改,因为找不到任何更改。

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

$ git pull
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 3), reused 0 (delta 0)
Unpacking objects: 100% (5/5), done.
From https://private/url/project/
   e56777c..fac7619  master     -> origin/master
Updating e56777c..fac7619
error: Your local changes to the following files would be overwritten by merge:
    ProjectSettings/EditorBuildSettings.asset
Please, commit your changes or stash them before you can merge.
Aborting

$ git status
On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)
nothing to commit, working directory clean

$ git pull
Updating e56777c..fac7619
error: Your local changes to the following files would be overwritten by merge:
    ProjectSettings/EditorBuildSettings.asset
Please, commit your changes or stash them before you can merge.
Aborting

$ git stash
No local changes to save

$ git fetch

$ git status
On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)
nothing to commit, working directory clean

$ git stash
No local changes to save

$ git merge
Updating e56777c..fac7619
error: Your local changes to the following files would be overwritten by merge:
    ProjectSettings/EditorBuildSettings.asset
Please, commit your changes or stash them before you can merge.
Aborting

$ git stash
No local changes to save

this question上尝试接受的答案,不起作用。我收到以下错误:

$ git fetch --all
Fetching origin

$ git reset --hard origin/master
error: Entry 'ProjectSettings/EditorBuildSettings.asset' not uptodate. Cannot merge.
fatal: Could not reset index file to revision 'origin/master'.

有人能够可靠地reproduce and fix the last error:'无法重置索引......'但他们建议的解决方法会为我产生以下错误:

$ git add .

$ git reset --merge fac7619
error: Entry 'ProjectSettings/EditorBuildSettings.asset' not uptodate. Cannot merge.
fatal: Could not reset index file to revision 'fac7619'.

无论如何强制git覆盖ProjectSettings?或者问它为什么认为当没有找到时会发生局部变化?

编辑:

好的,在完成reset --merge之后,我做了reset --hard然后git status通知我我落后于1次提交,这次我做git pull时所有内容都合并而没有任何问题。

那么,如何避免上述情况呢? 或者这是多操作系统环境中常见的事情? 我的工作流程相当一致。我从拉动,编辑,添加,提交,推动开始。但是,对于这个项目,有时候我使用的是Windows机器,有些我正在使用OSX。我在使用git的2年内没有遇到过这个问题。

2 个答案:

答案 0 :(得分:1)

  1. 从git方式移除ProjectSettings/EditorBuildSettings.asset(只需将其移至其他名称,例如ProjectSettings/EditorBuildSettings.asset.my
  2. 执行git pull。这次应该无缝完成。
  3. 比较ProjectSettings/EditorBuildSettings.assetProjectSettings/EditorBuildSettings.asset.my并确定哪个版本更正确。

答案 1 :(得分:1)

尝试在另一个分支上强制结帐,然后再次结帐,例如

git checkout origin/master -f
git checkout master -f

然后再拉一次:

git pull