Dav*_*vis 73 git ignore status git-submodules
在Linux上使用Git 1.8.1.1.存储库如下所示:
master
book
Run Code Online (Sandbox Code Playgroud)
子模块创建如下:
$ cd /path/to/master
$ git submodule add https://user@bitbucket.org/user/repo.git book
Run Code Online (Sandbox Code Playgroud)
该book
子模块是干净的:
$ cd /path/to/master/book/
$ git status
# On branch master
nothing to commit, working directory clean
Run Code Online (Sandbox Code Playgroud)
另一方面,主人显示书子模块有"新提交":
$ cd /path/to/master/
$ git status
# On branch 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: book (new commits)
#
no changes added to commit (use "git add" and/or "git commit -a")
Run Code Online (Sandbox Code Playgroud)
Git应该完全忽略子模块目录,这样主服务器也是干净的:
$ cd /path/to/master/
$ git status
# On branch master
nothing to commit, working directory clean
Run Code Online (Sandbox Code Playgroud)
master/.gitmodules
根据这个答案,文件内部如下:
[submodule "book"]
path = book
url = https://user@bitbucket.org/user/repo.git
ignore = dirty
Run Code Online (Sandbox Code Playgroud)
master/.gitmodules
根据以下答案更改为以下内容:
[submodule "book"]
path = book
url = https://user@bitbucket.org/user/repo.git
ignore = untracked
Run Code Online (Sandbox Code Playgroud)
master/.git/config
按照以下答案编辑到以下内容:
[status]
showUntrackedFiles = no
Run Code Online (Sandbox Code Playgroud)
将book目录添加到master ignore文件中:
$ cd /path/to/master/
$ echo book > .gitignore
Run Code Online (Sandbox Code Playgroud)
将book目录添加到master中,如下所示:
$ cd /path/to/master/
$ rm -rf book
$ git clone https://user@bitbucket.org/user/repo.git book
Run Code Online (Sandbox Code Playgroud)
book
子模块如何在存储库下的自己的存储库目录中master
但是git忽略了book
子模块?也就是说,不应显示以下内容:
#
# modified: book (new commits)
#
Run Code Online (Sandbox Code Playgroud)
如何git status
在主存储库中执行时禁止该消息?
一篇关于git submodule陷阱的文章表明这是一个不合适的子模块使用?
小智 97
赶紧跑:
$ git submodule update
Run Code Online (Sandbox Code Playgroud)
这将把子模块还原为旧提交(在parent-repo中指定),而不用子模块的最新版本更新父repo.
Nev*_*nel 56
要包含另一个无需在其超级仓库中跟踪的存储库,请尝试以下操作:
$ cd /path/to/master/
$ rm -rf book
$ git clone https://user@bitbucket.org/user/repo.git book
$ git add book
$ echo "book" >> .gitignore
Run Code Online (Sandbox Code Playgroud)
然后提交.
正如链接的git子模块陷阱文章中所述:
...父和子模块之间唯一的链接是子模块的签出SHA的记录值,该值存储在父提交中.
这意味着子模块不会通过其签出的分支或标记保存,但始终由特定的提交保存; 提交(SHA)保存到super-repo(包含子模块的文件)中,就像普通的文本文件一样(当然,它被标记为这样的引用).
当您检查子模块中的其他提交或在其中进行新提交时,超级仓库将看到其已检出的SHA已更改.那是你从modified (new commits)
线上得到的git status
.
要消除这种情况,您可以:
git submodule update
,这将重置子模块目前提交保存在超回购(详见该git submodule
手册页 ;或git add book && git commit
将新SHA保存到超级仓库中.正如评论中所提到的,考虑放弃book
子模块:在超级仓库中克隆它,如果不需要将其状态作为超级仓库的一部分进行跟踪.
gre*_*uze 19
您可以抑制两种更改通知(来自git 1.7.2).
第一个是未经跟踪的内容,当您对子模块进行更改但尚未提交时,会发生这种情况.父存储库注意到这些并且git状态相应地报告它:
modified: book (untracked content)
Run Code Online (Sandbox Code Playgroud)
您可以使用以下方法来抑制
[submodule "book"]
path = modules/media
url = https://user@bitbucket.org/user/repo.git
ignore = dirty
Run Code Online (Sandbox Code Playgroud)
但是,一旦您提交了这些更改,父存储库将再次注意并相应地报告它们:
modified: book (new commits)
Run Code Online (Sandbox Code Playgroud)
如果您想要抑制这些,则需要忽略所有更改
[submodule "book"]
path = book
url = https://user@bitbucket.org/user/repo.git
ignore = all
Run Code Online (Sandbox Code Playgroud)
Git 2.13(2017年第二季度)将添加另一种方法来包含一个子模块,该子模块不需要被其父级仓库跟踪.
在OP的情况下:
git config submodule.<name>.active false
Run Code Online (Sandbox Code Playgroud)
请参阅提交1b614c0,提交1f8d711,提交bb62e0a,提交3e7eaed,提交a086f92(2017年3月17日),并提交ee92ab9,提交25b31f1,提交e7849a9,提交6dc9f01,提交5c2bd8b(2017年3月16日),由Brandon Williams(mbrandonw
)提交.
(由Junio C gitster
Hamano合并- -在提交a93dcb0,2017年3月30日)
submodule
:解耦url和子模块的兴趣目前,
submodule.<name>.url
config选项用于确定给定的子模块是否对用户感兴趣.在我们希望在不同工作树中检出不同子模块的世界中,或者更通用的机制来选择哪些子模块是感兴趣的,这最终会很麻烦.在具有子模块的工作树支持的未来,将有多个工作树,每个工作树可能只需要检出的子模块的子集.
URL(可以获取子模块存储库的位置)在不同的工作树之间不应该有所不同.用户可以更方便地指定他们感兴趣的子模块组,而不是
git submodule init <path>
在他们想要在工作树中检出的每个子模块上运行" ".为此,引入了两个配置选项,
submodule.active
和submodule.<name>.active
.
- 该
submodule.active
配置拥有pathspec指定应在工作树中存在的子模块.
- 该
submodule.<name>.active
配置是用来表示该特定子模块,应在工作树存在的布尔标志.重要的是要注意
submodule.active
功能与其他配置选项不同,因为它需要一个pathspec.
这允许用户采用至少两个新的工作流程:
- 子模块可以与一个前导目录组合在一起,这样一个例如''
lib/
' 的路径将覆盖所有库模块,以允许那些对库模块感兴趣的人submodule.active = lib/
只需设置" "一次就可以说'lib/
'中的任何和所有模块都是有趣.- 一旦发现了pathspec属性功能,用户就可以使用属性对子模块进行标记以对其进行分组,以便可以使用具有属性要求的宽路径规范(例如'
:(attr:lib)
')来表示具有'lib
'属性的任何和所有模块都很有趣.
由于.gitattributes
文件就像.gitmodules
文件一样,由超级项目跟踪,当子模块在超级项目树中移动时,项目可以调整哪个路径获取属性.gitattributes
,就像它可以调整哪个路径有子模块一样.gitmodules
.
归档时间: |
|
查看次数: |
40472 次 |
最近记录: |