为什么git坚持在原点发生变化时我的更改是本地的,导致我无法进行更改?

时间:2012-03-26 21:34:35

标签: git branch

以下是该方案:

  1. 我克隆了我的代码库的暂存分支:

    git clone -b staging git@my.giturl.com:/my-repository.git .
    
  2. 我在其他地方进行了更改并将其推送到原点

  3. 我尝试将更改提取到我的结帐处:

    git pull origin
    
  4. 之前的陈述未能给我这个:

    Updating 7bb2dae..f711fb0
    error: Your local changes to the following files would be overwritten by merge:
        sites/all/modules/broker_auth/broker_auth.module
    Please, commit your changes or stash them before you can merge.
    Aborting
    

    broker_auth.module是我在别处更改的文件,但当地没有任何内容被触及。为什么说它已经改变了?我可以修复的唯一方法是执行以下操作(这需要一段时间,因为它会重新加载整个存储库)

    git reset --hard
    git pull origin
    

    在这种情况下我真的需要重置吗?我觉得我正在错误地管理我的分支,但是我无法弄清楚发生了什么。

3 个答案:

答案 0 :(得分:2)

您可以通过在拉动之前存储本地更改并在之后重新应用它们来解决此问题:

git stash
git pull
git stash apply

答案 1 :(得分:2)

我找到了问题的原因。最终我的服务器正在更改我的文件的权限,因此所有文件都被标记为已修改。我运行了以下命令git config core.filemode false,它基本上忽略了文件模式的更改,现在我的提取工作每次都是第一次。希望这有助于有类似问题的人。

答案 2 :(得分:1)

听起来,在您有机会合并之前,您只需拥有一个由您的环境或IDE更改的文件。

如果您确定更改不是您想要的,那么您只需要检查该文件(您的重置也可以)

我建议使用以下工作流程......(假设主分支)

git fetch (rather than a pull, which is a fetch and a merge)
git merge origin/master (assuming you are in the master branch)
....Fails here with your message....
git checkout sites/all/modules/broker_auth/broker_auth.module (to reset the file)
git merge origin/master (so you already have the repos, no need to hit the remote again)
相关问题