git要添加已经跟踪的文件 [英] git wants to add already tracked files

查看:503
本文介绍了git要添加已经跟踪的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PC上有一个大约70GB的存储库,当我将其复制(不是克隆文件,只是简单复制)到我的Mac上时,它表明某些文件在已被跟踪的同时未被跟踪.

当我添加它们时,它们似乎在回购对象信息中重复了,但是在工作树中却没有.因此,我对上次提交进行了硬重置,但文件再次显示为未跟踪.

如何解决此问题? (知道PC上的存储库运行良好)

I have a repository on a pc with approximate size of 70GB and when I copied it (not clone, just simple copying) to my mac it shows that some files are untracked while they are already tracked.

When I added them, they appeared to be duplicated in the repo objects info but not in the working tree of course. So I made a hard reset to the last commit but the files appeared again as untracked.

How can I solve this problem? (knowing that the repo on the pc is working well)

推荐答案

不要在计算机之间复制存储库的工作目录.

Don't copy a repository's working directory from computer to computer.

您的工作目录已检出相应行尾的文件. Windows计算机使用回车符和换行符来表示换行符,而Mac不使用换行符. 您应该已配置 PC在存储库中进行行尾转换.将文件从Windows复制到Mac会将具有Windows样式的行尾的文件复制到Mac,而不属于Mac.

Your working directory has checked out files in the appropriate line endings. Your Windows machine uses a carriage return and a line feed to indicate a newline, your Mac does not. You should have configured your PC to do line ending conversion in your repository. Copying the files from Windows to Mac introduces files with Windows-style line endings to your Mac, where they don't belong.

Git决定您的文件有未分段的更改 [1],因为行尾配置会指示客户端将Unix样式的行尾保留在存储库中,并在转换时转换为正确的行尾格式检查文件.这意味着,当您在PC上检出文件时,它们已转换为Windows样式的行尾.但是您的Mac希望更改存储库的行尾.

Git has decided that your files have unstaged changes[1] because your line ending configuration instructs your clients to keep Unix-style line endings in the repository and to convert to the proper line ending format when checking files out. This means that when you checked the files out on your PC, they were converted to Windows-style line endings. But your Mac expects to not alter line endings for the repository.

因此,您的存储库包含Unix格式的文件,而Mac具有Windows格式的文件.因此,当您运行git status时,Git会意识到工作目录中的文件与存储库中的文件不同. (仅在行尾不同),并告诉您文件有未暂存的更改.

So your repository contains files in Unix format, and your Mac has files in Windows format. So when you run git status, Git realizes that the files in the working directory are different than the files in the repository. (differing only in line endings) and tells you the files have unstaged changes.

还有其他原因不将存储库从一台计算机复制到另一台计算机.创建或克隆存储库(通过git initgit clone)时,Git会检测计算机的行为.有关系统的数据(例如,文件系统区分大小写还是不区分大小写,以及文件系统是否支持符号链接)存储在存储库的配置中.

There are other reasons not to copy a repository from one computer to another. Git detects the behavior of the computer when a repository is created or cloned (via git init or git clone). Data about the system like whether the filesystem is case-sensitive or case-insensitive, and whether the filesystem supports symbolic links is stored in the repository's configuration.

如果要将具有工作目录的存储库从Windows计算机复制到Mac,则您的存储库将不再支持符号链接.从Mac到Linux机器,您的存储库会非常混乱,因为它认为它不区分大小写.

If you were to copy a repository with a working directory from a Windows computer to a Mac, your repository would no longer support symbolic links. From a Mac to a Linux machine and your repository would get very confused because it thinks it's case insensitive.

最后,即使您在同一类型的计算机上复制存储库,甚至在同一台计算机本身上复制存储库,也可能会遇到问题. Git在索引中缓存了一些工作目录信息.复制工作目录应该会使该缓存无效,

Finally, even if you are copying a repository on the same type of computer - or even the same computer itself - you can run into problems. Git caches some working directory information in the index. Copying the working directory should invalidate that cache, but some Git clients may (incorrectly) obey the cache after a copy, which would give false information.

这是您可能确实要删除存储库并重新开始的几次之一.您可以删除工作目录中的所有文件,并清理配置.但是,此时,将这个存储库git clone到Mac上实际上要容易得多.

This is one of the few times where you probably really do want to remove your repository and start over. You could remove all the files in your working directory and clean up your configuration. But at this point, it's realistically much easier to just git clone this repository onto your Mac.

由于存储库很大,因此如果您不想花费网络流量开销,则可以简单地从复制的现有存储库中进行克隆. (它将忽略配置错误的工作目录文件和错误的配置.)例如,如果损坏的存储库位于badrepo:

Since the repository is large, if you do not want to spend the network traffic overhead, you can simply clone from the existing repository that you copied. (It will ignore both the misconfigured working directory files and the faulty configuration.) For example, if your damaged repository is in badrepo:

git clone badrepo goodrepo

[1]:术语:您的文件有未暂存的更改,您的文件不是未跟踪的. 未跟踪的文件是尚未在存储库中的文件.

[1]: Terminology: your files have unstaged changes, your files are not untracked. Untracked files are those that are not yet in the repository.

这篇关于git要添加已经跟踪的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆