简体   繁体   English

Git 克隆导致已删除和未跟踪的文件

[英]Git clone leads to deleted & untracked files

I am new to Git.我是 Git 的新用户。

I just installed Git (2.9.3) for Windows (10), then I opened git-bash and did a git clone <remoteURL> .我刚刚为 Windows (10) 安装了 Git (2.9.3),然后我打开了 git-bash 并做了一个git clone <remoteURL> A new folder is created with the whole copy of the remote repository, which is good.使用远程存储库的整个副本创建一个新文件夹,这很好。 But then I run a git status and I get a ton of deleted files (I suppose all the files that just got copied) ready to be committed , and the three main folders under the repository folder are untracked .但是后来我运行了git status ,我得到了大量deleted的文件(我想是刚刚复制的所有文件)准备to be committed ,并且存储库文件夹下的三个主要文件夹untracked The deleted files actually exist on my drive though! deleted的文件实际上存在于我的驱动器上!

I am pretty sure my git status should be clean instead.我很确定我的 git 状态应该是干净的。 What is happening?怎么了?

This about deleted files didn't help (I didn't use checkout ), neither did this about untracked files (I'm not using Mac OS).关于已删除文件没有帮助(我没有使用checkout ),关于未跟踪的文件也没有帮助(我没有使用 Mac OS)。

I was retrieving a huge project with very long paths.我正在检索一个路径很长的大型项目。 I forgot to set up Git to use long paths:我忘了设置 Git 以使用长路径:

git config --global core.longpaths true

After this, the cloning went fine and the status clean.在此之后,克隆进行得很顺利,状态也很干净。

It sounds like you've somehow loaded an empty index.听起来您以某种方式加载了一个空索引。 The normal way this happens in with the command git read-tree --empty , but that's not something you usually use/know as a new user of git.使用命令git read-tree --empty发生这种情况的正常方式,但这不是您作为 git 新用户通常使用/知道的。

Perhaps something went wrong with the clone.也许克隆出了点问题。 It's shouldn't be difficult to fix though, just run不过应该不难修复,只需运行

git reset

and the index should be restored to the contents of the latest commit.并且索引应该恢复到最新提交的内容。

This issue confuses not only the OP who "is new to git".这个问题不仅让“对 git 不熟悉”的 OP 感到困惑。 It also scares the sh*t out of me, a considerable git verteran.它也吓坏了我,一个相当大的 git verteran。 :-) :-)

Thanks for the hints from other answers here, I realize that it is caused by git happens to be NOT able to checkout some files whose names contains unsupported characters on current file system and/or OS.感谢此处其他答案的提示,我意识到这是由 git 引起的,它碰巧无法检出某些名称包含当前文件系统和/或操作系统上不受支持的字符的文件。 For example, I encountered this same error when I'm cloning a github wiki repo, some wiki pages happen to contain a : in its file name, they can be cloned fine on my Linux box, but (at a hindsight) obviously not on my Windows box.例如,当我克隆 github wiki 存储库时,我遇到了同样的错误,一些 wiki 页面的文件名中碰巧包含一个: ,它们可以在我的 Linux 机器上很好地克隆,但是(事后看来)显然不是我的 Windows 盒子。

Understanding the root cause gives us a confident decision on how/whether we fix this problem:了解根本原因使我们能够自信地决定如何/是否解决此问题:

  • We can fix it in the repo by renaming those offending filenames into shorter and/or containing only usual alphabet.我们可以通过将那些有问题的文件名重命名为更短和/或仅包含通常的字母表来修复它。
  • Or, technically we do NOT have to fix it at all.或者,从技术上讲,我们根本不必修复它。 If those offending filenames were just fine on their targetting platform, and we are working on some other content of this repo, we can continue our work as usual;如果那些有问题的文件名在他们的目标平台上没有问题,并且我们正在处理这个 repo 的其他一些内容,我们可以像往常一样继续我们的工作; we just need to remember to NOT commit those missing files as a deletion.我们只需要记住不要将那些丢失的文件作为删除提交。 (Been there, done that; Don't try this at home.) (去过那里,做到了;不要在家里尝试这个。)

If you experience problems on Windows might check your file names against these forbidden characters:如果您在 Windows 上遇到问题,可能会根据这些禁用字符检查您的文件名:

< (less than) < (小于)
> (greater than) > (大于)
: (colon) :(冒号)
" (double quote) " (双引号)
/ (forward slash) / (正斜杠)
\\ (backslash) \\(反斜杠)
| | (vertical bar or pipe) (垂直条或管)
? ? (question mark) (问号)
* (asterisk) * (星号)

Or files named with one of the reserved words below or one of these immediately followed by the extension: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9.或使用以下保留字之一或其中之一紧跟扩展名命名的文件: CON、PRN、AUX、NUL、COM1、COM2、COM3、COM4、COM5、COM6、COM7、COM8、COM9、LPT1、LPT2、 LPT3、LPT4、LPT5、LPT6、LPT7、LPT8 和 LPT9。

More details can be found here .可以在此处找到更多详细信息。

In case you end up here and the longpath property did not work AND you run on Windows and use Git Bash you might have files using reserved keywords in Windows.如果您最终到达这里并且 longpath 属性不起作用并且您在 Windows 上运行并使用 Git Bash,那么您可能会在 Windows 中使用保留关键字的文件。 Ie, I had files with nul in it, and those got deleted after clone.即,我有包含nul文件,这些文件在克隆后被删除。 I spent half a day finding it was this reserved keyword thing.找了半天发现是这个保留关键字的东西。

The solution for that is simply renaming the file (on your other machine / OS where you could create it).解决方案只是重命名文件(在您可以创建它的其他机器/操作系统上)。 Push it, and then redo the clone operation on your Windows machine.推送它,然后在您的 Windows 机器上重做克隆操作。

In my case, I had cloned the repo in a case insensitive filesystem on my Mac, however the repo included a file named Config and a directory named config , which the filesystem considered as the same thing.就我而言,我在 Mac 上的一个不区分大小写的文件系统中克隆了 repo,但是该 repo 包含一个名为Config的文件和一个名为config的目录,文件系统将其视为同一件事。 So, upon clone, it displayed that the file Config was deleted.因此,在克隆时,它显示文件Config已被删除。

The fix was to clone the repo on a case sensitive file system.修复是在区分大小写的文件系统上克隆 repo。

也可以是文件名中的不可见字符,请在其他系统上查看 ;)

I faced the similar issue with windows 10 , I checked other windows as well where git was working fine , My git version was 2.24.xx.我在 windows 10 上遇到了类似的问题,我检查了其他 windows 以及 git 工作正常的地方,我的 git 版本是 2.24.xx。 i installed the git older version of git 2.16.x and it solves the problem.我安装了 git 2.16.x 的旧版本,它解决了问题。 Try it and let know试试看,让你知道

The behavior which showing some files as modified could be related to line ending setting and multiple client used.将某些文件显示为已修改的行为可能与行尾设置和使用的多个客户端有关。 Every operating system handles line endings in it's own way.每个操作系统都以自己的方式处理行尾。 So if you are working on repositry where in the the files are edited in multiple operating systems, you may see unexpected results因此,如果您正在处理在多个操作系统中编辑文件的存储库,您可能会看到意想不到的结果

The following command will solve the issue permanently以下命令将永久解决问题

git config --global core.autocrlf input git 配置 --global core.autocrlf 输入

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

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