git - 签出到另一个分支时,文件作为未暂存的更改被删除
问题描述
合并后,我面临一个奇怪的问题,即签出另一个分支会导致未暂存的更改 - 删除一些文件。
PS>git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
PS>git checkout master_test
Switched to branch 'master_test'
Your branch is up to date with 'origin/master_test'.
PS>git status
On branch master_test
Your branch is up to date with 'origin/master_test'.
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: Modules/CimCmdlets/CimCmdlets.psd1
...
由于它仅在我这样做时才会发生git checkout
,因此我假设文件是由 git 本身删除的。如何确定这些文件被删除的原因?
解决方案
由于 Windows 默认情况下不区分大小写,因此您可能有两个名称相同但大小写不同的文件。WinMerge 等 Windows 工具无法发现这一点,因为这两个文件中只有一个被签出。
我将在默认情况下不区分大小写的 OS X 上演示这一点。我在区分大小写的卷上创建了一个 Git 存储库,其中包含FOO
和foo
文件。现在我正在一个不区分大小写的文件系统上检查它。
$ git clone /Volumes/case_sensitive/tmp/test
Cloning into 'test'...
done.
warning: the following paths have collided (e.g. case-sensitive paths
on a case-insensitive filesystem) and only one from the same
colliding group is in the working tree:
'FOO'
'foo'
$ ls
.git foo
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: FOO
no changes added to commit (use "git add" and/or "git commit -a")
您可以使用git ls-files
.
$ git ls-files
FOO
foo
我们可以通过将一个文件重命名为独特的东西来解决这个问题......
$ git mv foo foo2
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: foo -> foo2
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: FOO
现在它已经不碍事了,我们可以签出另一个文件。
$ git co FOO
Updated 1 path from the index
$ ls
.git FOO foo2
$ git st
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: foo -> foo2
在你修复foo
了以前使用的任何代码之后foo2
,提交。
推荐阅读
- magento - 将客户欢迎电子邮件的副本发送到 magento 2 中的另一个地址邮件的选项
- python - 将 exel 单元格值附加到仅包含数据的 Openpyxl 列表
- mysql - 根据列值链接另一个表
- java - 如何解决 java.lang.String 不能转换为 java.sql.Date?
- reactjs - React TS 共享样式组件道具
- angular - 单击角度按钮时,步进器的 SelectedIndex 未更新
- flutter - 几秒钟后如何停止视频录制?
- ios - 为什么当我缩放到滚动视图的右侧时,它会弹回中心?
- python - 在类继承中使用默认值传递参数的最安全方法是什么?
- opencv - OpenCV Haar 级联创建