"将被合并覆盖"是什么意思?

dat*_*tps 8 git git-pull

从基于团队的Git远程存储库中提取时,我收到以下消息:

"C:\Program Files (x86)\Git\bin\git.exe" pull --progress "origin" +refs/heads/master:refs/remotes/origin/master
Updating 71089d7..4c66e71
error: Your local changes to the following files would be overwritten by merge:
    Source/Reporting/Common/Common.Dal.csproj
Please, commit your changes or stash them before you can merge.
Aborting
Done
Run Code Online (Sandbox Code Playgroud)

Git中哪些规则(或功能),确保了我在工作目录中修改该文件确实得到由拉覆盖?

换句话说,在什么情况下它被拉动覆盖?或者...我需要做什么才能强制拉动覆盖我刚刚修改过的文件?

sle*_*man 8

什么规则会产生"将被覆盖"的警告?

如果您已修改了在远程存储库中也有修改但尚未提交的文件.

什么规则会避免"会被覆盖"警告?

如果没有未提交的文件也在远程仓库中进行了修改.

我需要做什么...

这取决于你真正想要的东西:

  1. 您想强制拉取覆盖文件

    显然,如果你真的想要这个,你不关心你刚刚做出的改变,也不介意删除它们.如果是这样,你只需:

    git reset --hard
    git pull
    
    Run Code Online (Sandbox Code Playgroud)
  2. 你想要你的改变和拉动的变化

    在我看来,处理这个问题的最简单方法是提交你的更改,然后做一个拉动.然后,如果存在合并冲突,请使用常用机制来解析合并(提示:配置difftool和mergetool,以便您可以使用GUI工具(如meld或diffmerge等)轻松解决冲突.做就是了:

    git add $the_affected_file
    git commit
    git pull
    
    Run Code Online (Sandbox Code Playgroud)
  3. 您想要两个更改,但您还没准备好提交

    我个人认为你不应该做好准备.但有时会发生部分破坏您正在调试的代码并且您真的不想提交的情况.在这种情况下,您可以暂时隐藏更改,然后在拉动后取消暂停:

    git stash
    git pull
    git stash pop
    
    Run Code Online (Sandbox Code Playgroud)

    如果在弹出隐藏后存在冲突,则以通常的方式解决它们.注意:如果您因为冲突而未准备好丢失存储的代码git stash apply,pop则可能需要执行此操作.


Zby*_*000 5

该消息意味着您对文件进行了本地修改但未提交。运行时pull,工作树中的文件将从远程存储库更新。如果 git 发现该文件被您修改并提交并位于远程存储库中,它只会尝试合并更改并更新索引和工作树。但对于仅本地修改的文件且尚未提交的文件,它将停止。

因此,您必须commit首先进行更改,或者stash按照消息中的建议进行更改。没有办法避免它,因为它会导致索引和工作树不一致。

保留本地更改的典型场景是(如 中所示git help stash):

           git pull # first attempt of pull
            ...
           # Here you see the complains about locally modified files
           git stash # will save your changes into stash
           git pull  # pull now succeeds as there are no locally modified files
           git stash pop # pop the stash and apply the changes
Run Code Online (Sandbox Code Playgroud)