繁体   English   中英

签出到另一个分支时,文件作为未暂存的更改被删除

[英]Files getting deleted as unstaged changes when checking out to another branch

合并后,我面临一个奇怪的问题,即签出到另一个分支会导致未暂存的更改 - 删除某些文件。

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 本身删除。 如何确定这些文件被删除的原因?

编辑:这些分支上的文件之间没有区别,包括名称。 例如: WinMerge 文件夹之间的差异

由于默认情况下 Windows 不区分大小写,因此您可能有两个名称相同但大小写不同的文件。 WinMerge 等 Windows 工具无法发现这一点,因为只有两个文件中的一个被检出。

我将在默认情况下也不区分大小写的 OS X 上演示这一点。 我在区分大小写的卷上创建了一个 Git 存储库,其中包含FOOfoo文件。 现在我正在一个不区分大小写的文件系统上检查它。

$ 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")

该警告是在 2.20.0 中添加的

您可以使用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 ,提交。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM