忽略git子模块的新提交 [英] Ignore new commits for git submodule

查看:303
本文介绍了忽略git子模块的新提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景



在Linux上使用Git 1.8.1.1。该库看起来如下所示:

  master 
book

子模块创建如下:

  $ cd / path / to / master 
$ git submodule add https://user@bitbucket.org/user/repo.git book

book 子模块是干净的:

  $ cd / path / to / master / book / 
$ git status
#分支大师
没有提交,工作目录干净



问题



另一方面,主人显示本书有新提交子模块:

  $ cd / path / to / master / 
$ git status
#在分支主机上
#没有为commit提交更改:
#(使用git add< file> ...更新将提交的内容)
#(使用git checkout - <文件> ...放弃工作目录中的更改)

#修改:书(新提交)

无变化es添加到提交(使用git add和/或git commit -a)

Git应该完全忽略子模块目录,以便master也是干净的:

  $ cd / path / to / master / 
$ git status
#分支大师
没有提交,工作目录干净



失败尝试#1 - 脏



文件 master / .gitmodules 的内容如下所示回答

  [submodulebook] 
path = book
url = https://user@bitbucket.org/user/repo.git
ignore = dirty

失败尝试#2 - 未跟踪



更改主根据以下回答,将/.gitmodules 更改为以下内容:

  [submodulebook] 
path = book
url = https://user@bitbucket.org/user/repo.git
ignore = untracked



失败尝试#3 - showUntrackedFiles



编辑 master / .git / config 回答

  [status] 
showUntrackedFiles = no



Failed Attempt#4 - ignore



将图书目录添加到主忽略文件中:

  $ cd / path /到/ master / 
$ echo book> .gitignore



失败尝试#5 - 克隆



<如下所示:

  $ cd / path / to / master / 
$ rm -rf book
$ git clone https://user@bitbucket.org/user/repo.git book



$ h
$ b $ book 子模块如何在其自己的存储库目录下 master repository还有git忽略 book 子模块?即,以下内容不应该显示:

 
#修改:book(新提交)

如何在执行 git status 在主存储库中?



一篇关于 git子模块陷阱表明这是一个不适当的子模块用法?

解决方案为了包含另一个仓库,不需要在其超级仓库中进行跟踪,请尝试以下操作:

  $ cd / path / to / master / 
$ rm -rf book
$ git clone https://user@bitbucket.org/user/repo.git book
$ git add book
$ echobook>> .gitignore

然后提交。



在链接的 git submodule陷阱文章中指出:
$ b


...父节点与子模块之间唯一的链接是子模块检出的SHA的记录值在父提交中。

这意味着子模块不会被其签出的分支或标记保存,而总是通过特定承诺;该提交(SHA)被保存到super-repo(包含子模块的那个),就像一个普通的文本文件(当然,它被标记为这样的引用)。



当您在子模块中签出另一个commit 或在其中进行新的提交时,super-repo将看到其签出的SHA已更改。那就是当你从 git status 获得修改过的(新提交)行。



为了消除这种情况,您可以:


  • git子模块更新,这会将子模块重置为当前保存在超级回购中的提交(有关详细信息,请参阅 git submodule manpage ;或

  • git add book&& git commit 将新的SHA保存到超级回购站中。



正如评论中提到的,考虑放弃 book 子模块:如果不需要跟踪其状态作为超级回购的一部分,则将其克隆在超级回购中。


Background

Using Git 1.8.1.1 on Linux. The repository looks as follows:

master
  book

The submodule was created as follows:

$ cd /path/to/master
$ git submodule add https://user@bitbucket.org/user/repo.git book

The book submodule is clean:

$ cd /path/to/master/book/
$ git status
# On branch master
nothing to commit, working directory clean

Problem

The master, on the other hand, shows there are "new commits" for the book submodule:

$ 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")

Git should ignore the submodule directory completely, so that the master is also clean:

$ cd /path/to/master/
$ git status
# On branch master
nothing to commit, working directory clean

Failed Attempt #1 - dirty

Inside the file master/.gitmodules is the following, as per this answer:

[submodule "book"]
        path = book
        url = https://user@bitbucket.org/user/repo.git
        ignore = dirty

Failed Attempt #2 - untracked

Changed master/.gitmodules to the following, as per this answer:

[submodule "book"]
        path = book
        url = https://user@bitbucket.org/user/repo.git
        ignore = untracked

Failed Attempt #3 - showUntrackedFiles

Edited master/.git/config to the following, as per this answer:

[status]
   showUntrackedFiles = no

Failed Attempt #4 - ignore

Added the book directory to the master ignore file:

$ cd /path/to/master/
$ echo book > .gitignore

Failed Attempt #5 - clone

Added the book directory to the master as follows:

$ cd /path/to/master/
$ rm -rf book
$ git clone https://user@bitbucket.org/user/repo.git book

Question

How can the book submodule be in its own repository directory under the master repository yet have git ignore the book submodule? That is, the following should not display:

#
#       modified:   book (new commits)
#

How to suppress that message when executing git status in the master repository?

An article about git submodule pitfalls suggests this an inappropriate submodule usage?

解决方案

To include another repository, that needn't be tracked in its super-repo, try this:

$ cd /path/to/master/
$ rm -rf book
$ git clone https://user@bitbucket.org/user/repo.git book
$ git add book
$ echo "book" >> .gitignore

Then commit.

As stated in the linked git submodule pitfalls article:

... the only linkage between the parent and the submodule is [the] recorded value of the submodule’s checked-out SHA which is stored in the parent’s commits.

That means that a submodule is not saved by its checked-out branch or tag, but always by a specific commit; that commit (SHA) is saved into the super-repo (the one containing the submodule) like a normal text file (it's marked as such a reference, of course).

When you check out a different commit in the submodule or make a new commit in it, the super-repo will see that its checked out SHA has changed. That's when you get the modified (new commits) line from git status.

To eliminate that, you can either:

  • git submodule update, which will reset the submodule to the commit currently saved in the super-repo (for details see the git submodule manpage; or
  • git add book && git commit to save the new SHA into the super-repo.

As mentioned in the comments, consider abandoning the book submodule: clone it inside the super-repo, if tracking of its state as part of the super-repo is not necessary.

这篇关于忽略git子模块的新提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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