作者:储兰兰快乐 | 来源:互联网 | 2022-11-26 08:23
请观察:
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 !]>
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"
}
}
因此,我不想中止,而是想识别有问题的文件并基本上复制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 !]>
哪个很容易解析.但今天,我得到了一些不同的东西:
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 !]>
我不知道这是否与我的Powershell控制台有某种关系或者最近的一些git更新有所影响,我已经自动安装而没有注意到它.