简体   繁体   English

'git add。'不起作用

[英]'git add .' doesn't work

I am currently trying to setup Git for a project I have been working on for a while. 我正在尝试为我已经工作了一段时间的项目设置Git。 I do remember quite a while ago setting up Git but never used it for various reasons. 我记得很久以前设置Git但从未出于各种原因使用过它。 Now I want to use it i am getting a strange issue that I believe is related to an old install. 现在我想使用它我得到一个奇怪的问题,我认为这与旧安装有关。

To start a fresh I installed a fresh Ubuntu OS so that there would be no Git install present and I copied the project (Grails) over. 为了重新开始,我安装了一个新的Ubuntu操作系统,这样就不会有Git安装,我复制了项目(Grails)。 I then navigated to the directory and run the following commands: 然后我导航到该目录并运行以下命令:

git init

git remote add origin https://USERNAME@bitbucket.org/USERNAME/APPNAME.git

Then I ran: 然后我跑了:

git add .

This is where i get the error below: 这是我得到以下错误的地方:

fatal: Not a git repository: /home/user/workspace/App_V3/.git/modules/plugins/grails-spring-security-ui

This error is weird as this doesn't even match the directory I am in as the directory is below: 这个错误很奇怪,因为它甚至不匹配我所在的目录,因为目录如下:

/home/user/Workspace/App_V7/ / home / user中/工作区/ App_V7 /

I am thinking that originally I may have setup the Git in the App_V3 folder on the old OS but don't know why it still points to that directory as I have run the code below to re-initialize it: 我想我原本可能在旧操作系统的Ap​​p_V3文件夹中设置了Git,但不知道为什么它仍然指向该目录,因为我已经运行下面的代码重新初始化它:

rm -rf .git
git init

Can someone please help me with this as its really frustrating :S 有人可以帮助我,因为它非常令人沮丧:S

Thanks in advance 提前致谢

Moving repositories with submodules is problematic 移动具有子模块的存储库是有问题的

I am thinking that originally I may have setup the Git in the App_V3 folder on the old OS 我想原来我可能已经在旧操作系统的Ap​​p_V3文件夹中设置了Git

This is the source of the problem. 这是问题的根源。

What matters is the version of git when the repository (or more specifically, the referenced submodule) was originally created. 重要的是当最初创建存储库(或更具体地,引用的子模块)时的git版本。

Consider a repository with one submodule in vendor/awesome , how git behaved when creating the submodule is quite different. 考虑一个在vendor/awesome有一个子模块的存储库,git在创建子模块时的行为方式是完全不同的。

git version < 1.7.8 git版本<1.7.8

The contents of vendor/awesome/.git is a folder - just like any git checkout so for example the folder structure of a checkout would be: vendor/awesome/.git的内容是一个文件夹 - 就像任何git checkout一样,例如checkout的文件夹结构如下:

.gitmodules
.git
    ...
vendor/
    awesome
        .git
            config
            HEAD
            index
            packed-refs
            ...

There's no problem moving this kind of repository around, as there are no paths stored anywhere. 移动这种存储库没有问题,因为没有路径存储在任何地方。

git version 1.7.8 or 1.7.9 git版本1.7.8或1.7.9

1.7.8 moved the location of a submodule's .git folder 1.7.8移动了子模块的.git文件夹的位置

When populating a new submodule directory with "git submodule init", the $GIT_DIR metainformation directory for submodules is created inside $GIT_DIR/modules// directory of the superproject and referenced via the gitfile mechanism. 当使用“git submodule init”填充新的子模块目录时,子模块的$ GIT_DIR元信息目录在超级项目的$ GIT_DIR / modules //目录中创建,并通过gitfile机制引用。 This is to make it possible to switch between commits in the superproject that has and does not have the submodule in the tree without re-cloning. 这样就可以在没有重新克隆的情况下在超级项目中提交和在树中没有子模块的提交之间进行切换。

Therefore vendor/awesome/.git is not a folder, it is a file with the following contents: 因此vendor/awesome/.git不是文件夹,它是一个包含以下内容的文件:

gitdir: /absolute/path/to/main/repo/.git/modules/vendor/awesome

And the overal folder structure is: 整个文件夹结构是:

.gitmodules
.git
    ...
    modules
        vendor
            awesome
                config
                HEAD
                index
                packed-refs
                ...

vendor/
    awesome
        .git <- a file

The contents of .git/modules/vendor/awesome/config specifies where the working tree is: .git/modules/vendor/awesome/config指定工作树的位置:

[core]
   ...
   worktree = /absolute/path/to/main/repo/vendor/awesome

This was a pretty awesome change - however it introduced a problem, as absolute paths were used to reference locations. 这是一个非常棒的变化 - 但它引入了一个问题,因为绝对路径用于引用位置。

git version >= 1.7.10 git version> = 1.7.10

In version 1.7.10 the use of absolute paths in submodules was modified 1.7.10版中,修改了子模块中绝对路径的使用

The whole directory that houses a top-level superproject managed by "git submodule" can be moved to another place. 容纳由“git submodule”管理的顶级超级项目的整个目录可以移动到另一个地方。

Now vendor/awesome/.git if generated with this or a later version of git would contain: 现在vendor/awesome/.git如果使用此版本或更高版本的git生成,则包含:

gitdir: ../../.git/modules/vendor/awesome

The contents of .git/modules/vendor/awesome/config specifies where the working tree is: .git/modules/vendor/awesome/config指定工作树的位置:

[core]
   ...
   worktree = ../../../../vendor/awesome

Once again, there's no problem moving this kind of repository around, as paths a relative to the main repository. 再一次,将这种类型的存储库作为相对于主存储库的路径移动是没有问题的。

Moving repositories 移动存储库

With an old, or a new version of git - you're good. 使用旧的或新版本的git - 你很好。

If you're unfortunate enough to work on a repository created in 1.7.8 or 1.7.9 (which from the evidence in the question seems to be the case) and move the repository - there are 2 solutions : 如果您不幸在1.7.8或1.7.9中创建的存储库(从问题中的证据似乎就是这种情况)开始工作移动存储库 - 有两种解决方案

  1. Clone again 再次克隆
  2. Correct paths in submodule .git files, and the corresponding worktree config setting 更正子模块.git文件中的路径,以及相应的工作树配置设置

I moved all of the files one at a time to a new folder and then seemed to work fine :) 我将所有文件一次一个地移动到一个新文件夹然后似乎工作得很好:)

Thanks for the help 谢谢您的帮助

Instead of 代替

git init
git remote add origin https://USERNAME@bitbucket.org/USERNAME/APPNAME.git

you should use 你应该使用

git clone origin https://USERNAME@bitbucket.org/USERNAME/APPNAME.git .

since you want to clone an existing repository and not re-create it. 因为您要克隆现有存储库而不是重新创建它。

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

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