请观察:
C:\Dayforce\test [master ?2 +0 ~2 -0 !]> git pull
error: Your local changes to the following files would be overwritten by merge:
2.txt
Please commit your changes or stash them before you merge.
Aborting
Updating 2dc8bd0..ea343f8
C:\Dayforce\test [master ?2 +0 ~2 -0 !]>
Run Code Online (Sandbox Code Playgroud)
git有一个命令,可以告诉我哪些未提交的文件导致此错误?我可以通过git pull看到它们显示,但我真的不想解析git pull输出.
我完全了解pull.rebase和rebase.autostash配置选项,请不要提起它们.
编辑1
可以先执行git pull.实际上,识别有问题文件的逻辑将在git pull失败后完成.我在Powershell中认识到的方式是:
git pull
# Possible exit codes:
# 1 - either local changes or pull merge conflict (but the merge has not been started yet)
# 128 - a merge is in progress
if ($LASTEXITCODE)
{
git merge HEAD 2> $null # Disambiguate the exit code
if ($LASTEXITCODE -eq 128)
{
# Two options:
# - pull merge conflict
# - a merge is in progress
git mergetool
}
else
{
throw "Cannot pull due to uncommitted changes"
}
}
Run Code Online (Sandbox Code Playgroud)
因此,我不想中止,而是想识别有问题的文件并基本上复制rebase.autostash,但没有rebase.
编辑2
我以前认为git pull会输出类似的东西,以防止与未提交的更改发生冲突:
C:\xyz\test [master ?4 ?1 +0 ~3 -0 !]> git pull
error: Your local changes to the following files would be overwritten by merge:
2.txt
a.txt
Please commit your changes or stash them before you merge.
Aborting
C:\xyz\test [master ?4 ?1 +0 ~3 -0 !]>
Run Code Online (Sandbox Code Playgroud)
哪个很容易解析.但今天,我得到了一些不同的东西:
C:\xyz\test [master ?4 ?1 +0 ~2 -0 | +0 ~1 -0 !]> git pull
error: Your local changes to the following files would be overwritten by merge:
1.txt a.txt
C:\xyz\test [master ?4 ?1 +0 ~2 -0 | +0 ~1 -0 !]>
Run Code Online (Sandbox Code Playgroud)
我不知道这是否与我的Powershell控制台有某种关系或者最近的一些git更新有所影响,我已经自动安装而没有注意到它.
\n\n\n我不知道这是否与我的 Powershell 控制台以某种方式被搞砸有关,或者与最近的一些 git 更新有关
\n
Git 2.19 最近更改了合并报告此错误的方式,提交号为 9270239(2018 年 7 月)
\n\n这是基于merge-recursive.c#merge_trees,它跟踪两棵树以检测被覆盖的公共文件。
\n问题是:
在你的情况下,由于 git pull 已经完成了它的获取部分,但没有完成它的合并部分,你可以做一个git diff -\xe2\x80\x93name-only HEAD origin/yourFetchedBranch以便将工作树与获取的内容进行比较。
这应该列出不同的文件,包括您的2.txt.
\n\n\n它不会给我所有将要更改的文件而不仅仅是冲突的文件吗?
\n
是的,会的。
\n对于每个文件,您仍然需要检查它是否是当前已修改(未暂存或已暂存但未提交)文件列表的一部分:
git ls-files --other --modified --exclude-standard\ngit diff --name-only --cached\nRun Code Online (Sandbox Code Playgroud)\n