gpt4 book ai didi

混帐添加。在具有 .git 文件夹的子目录上失败,即使被忽略

转载 作者:太空狗 更新时间:2023-10-29 13:44:55 26 4
gpt4 key购买 nike

我们有一个很深的目录结构,在不同级别有多个 README 文件。例如:

gitignoretest/
|-- 00README
|-- dir1
| |-- 00README
| |-- dir1
| | |-- 00README
| | |-- dir1
| | |-- dir2
| | |-- dir3
| | |-- file1
| | `-- file2
| |-- dir2
| | |-- 00README
| | |-- dir1
| | |-- dir2
| | |-- dir3
| | |-- file1
| | `-- file2
| |-- dir3
| | |-- 00README
| | |-- dir1
| | |-- dir2
| | |-- dir3
| | |-- file1
| | `-- file2
| |-- file1
| `-- file2
|-- dir3
| |-- 00README
| |-- dir1
| | |-- 00README
| | |-- dir1
| | | |-- 00README
| | | |-- dir1
| | | |-- dir2
| | | |-- dir3
| | | |-- file1
| | | `-- file2
| | |-- dir2
| | | |-- 00README
| | | |-- dir1
| | | |-- dir2
| | | |-- dir3
| | | |-- file1
| | | `-- file2

...
...

我们只想对 00README 文件进行版本控制。我们用 this 成功测试了这个.gitignore

.gitignore

# Ignore everything
*

# But not these files...
!.gitignore
!00README
# etc...

# ...even if they are in subdirectories
!*/

但是,在真实 场景中,其中一个子目录是 conda 安装,其中一些包包含它们自己的 .git 目录。当我执行 git add . 时,它失败并显示消息:

fatal: Not a git repository: Applications/conda/lib/STAR-Fusion/STAR-Fusion.wiki/../.git/modules/STAR-Fusion.wiki

真实场景是 ../TopLevel/Applications/...../TopLevel/.gitignore。以下是我尝试过的方法:

../TopLevel/.gitignore

# Ignore everything
*
/Applications/conda/**/*
/Applications/miniconda3/**/*
/Applications/newconda/**/*

Applications/conda/**/*
Applications/miniconda3/**/*
Applications/newconda/**/*

/**/.git
**/.git

/**/.git/**
**/.git/**

# But not these files...
!.gitignore
!00README.md
!USE_APPS
# etc...

# ...even if they are in subdirectories
!*/

但没有达到目标。


编辑
为了解决@VonC 提到的带有 .git 文件夹的“取消跟踪”子目录的问题,我提出了一个全新创建的 git 存储库。注意:作为远程添加的存储库是新生成的 --bare 存储库。

balter@server:/home/.../TopLevel$ rmdir .git
balter@server:/home/.../TopLevel$ git init
Initialized empty Git repository in /home/.../TopLevel/.git/
balter@server:/home/.../TopLevel$ git remote add origin git@server.ohsu.edu:path/repo.git
balter@server:/home/.../TopLevel$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
# 00README.md
# Applications/
# InstallationPackages/
# USE_APPS
# gitignoretest/
nothing added to commit but untracked files present (use "git add" to track)
balter@server:/home/.../TopLevel$ git add .
fatal: Not a git repository: Applications/conda/lib/STAR-Fusion/STAR-Fusion.wiki/../.git/modules/STAR-Fusion.wiki

最佳答案

如果你想将所有树结构视为一个存储库,你需要先删除嵌套的 .git 子文件夹:参见“Initial push to GitHub Missing Sub Directory”。

关于忽略规则,如果你想忽略除OOREMEADE文件之外的所有内容,你需要先排除文件夹

*
!**/

然后你可以排除文件:

!00README

首先确保这些文件未被跟踪(git status)

Our Applications directory has a conda installation that seems to install many packages by cloning git repositories. If I go and delete all the .git directories then whenever I run conda update, either it will fail because it no longer has the repos it needs, or it will re-clone them.

首先,您不要忽略 .git 文件夹:它们的父文件夹代表嵌套的 git 存储库。这是您要忽略的文件夹(.git 文件夹的父文件夹),这样 git add . 就不会记录 gitlink ( special entry in index of the parent repo )

其次,“不是 git 存储库:.../../.git/modules/...”表示 conda 嵌套存储库具有 submodules ,谁的support is still in progress with conda : 该 conda 安装文件夹需要 git submodule update --init --recursive 才能初始化正确的嵌套子模块。

关于混帐添加。在具有 .git 文件夹的子目录上失败,即使被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42651913/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com