TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Git Submodules: Adding, Using, Removing, Updating (2009)

110 点作者 tigerlily超过 4 年前

22 条评论

OskarS超过 4 年前
Here&#x27;s the lesson I&#x27;ve learned from my experience with submodules in git in several different companies: avoid them like the plague. NEVER USE THEM FOR ANYTHING. Use any other solution available to you: use package managers, use monorepos, use subtrees, just copy&#x2F;paste the files in, avoid the dependency entirely, do ANYTHING it takes to avoid using submodules.<p>They just become a constant source of friction. Basically every action you do in git, there&#x27;s some tiny bit of annoyance caused by submodules, which adds up to tearing your hair out. Like, read this StackOverflow question and answer, and tell me this is something you want to be dealing with on daily basis (and you will be, you&#x27;ll regularly be dealing with far worse): <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;9314365&#x2F;git-clean-is-not-removing-a-submodule-added-to-a-branch-when-switching-branches" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;9314365&#x2F;git-clean-is-not...</a><p>The correct way to handle dependencies in general is package managers, but if for some reason that is not available to you, and you wish to avoid git subtree for some reason, copy&#x2F;pasting the code from the other repository and making a note in the commit message which commit in the dependency repo you copied from is a far preferable solution. Yeah, you lose the history of the sub-repo, but it&#x27;s well worth it to avoid the complications from using submodule (and you never examine the history of the submodule anyway, how often do you look at the history of your dependencies?).<p>Submodules: not even once.
评论 #26165852 未加载
评论 #26165620 未加载
评论 #26165673 未加载
评论 #26166108 未加载
评论 #26166217 未加载
评论 #26167273 未加载
评论 #26167603 未加载
评论 #26165644 未加载
评论 #26165995 未加载
评论 #26166930 未加载
评论 #26170284 未加载
评论 #26169842 未加载
评论 #26167371 未加载
评论 #26167791 未加载
评论 #26167670 未加载
flohofwoe超过 4 年前
IME submodules are mostly fine for external dependencies that only very rarely change and remain pinned at a specific version over weeks or months.<p>Giving submodules a special set of git commands, and providing the users so many easy opportunities to shoot themselves in the foot are baffling design decisions though.<p>E.g. I&#x27;d really like to know why &quot;git clone --recursive&quot; isn&#x27;t the default.
评论 #26165257 未加载
评论 #26165355 未加载
评论 #26166078 未加载
评论 #26167589 未加载
NalNezumi超过 4 年前
Oh I remember at previous work when the (now lead engineer) decided that the main repo that depended on actively changing 4 subrepo currently included as subtrees had to be changed to submodule. This in a rapidly developing repo where the main branch hadn&#x27;t been update for 18 months while &quot;develop&quot; branch was switched to other &quot;sub&quot; branches on monthly basis.<p>Needless to say it was a total shitshow. My first experience of how &quot;wanting to use the cool stuff I just found out about&quot; type of perso in position of decision making can be catastrophic. The dude wanted to switch all code base to C++20 in 2020, 3 days after the conference
BuckarooBanzay超过 4 年前
Despite all the comments saying to avoid submodules i can only recommend them.<p>I&#x27;m using them in several of my game servers as a &quot;meta-repo&quot; that points to other git repositories (for example here: <a href="https:&#x2F;&#x2F;github.com&#x2F;pandorabox-io&#x2F;pandorabox-mods" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pandorabox-io&#x2F;pandorabox-mods</a>)<p>It makes updating, finding&#x2F;fixing bugs and testing much easier (we are using github&#x27;s dependabot to update and kick off initial tests)
评论 #26166566 未加载
评论 #26167098 未加载
wheybags超过 4 年前
I&#x27;ve found that git subtrees are a much better option. Good intro here:<a href="https:&#x2F;&#x2F;www.atlassian.com&#x2F;git&#x2F;tutorials&#x2F;git-subtree" rel="nofollow">https:&#x2F;&#x2F;www.atlassian.com&#x2F;git&#x2F;tutorials&#x2F;git-subtree</a><p>They&#x27;re like submodules, but you can edit them and they&#x27;re embedded in your history, not just a reference.
评论 #26165912 未加载
评论 #26166661 未加载
评论 #26166896 未加载
评论 #26167564 未加载
Pxtl超过 4 年前
I&#x27;m using submodules in a project and I have to agree - they&#x27;re awful. The fact that their ergonomics are so bad in as trivial cases as <i>switching branches</i> is flabbergasting.<p>I mean, it was the Right Tool for the Job for my use-case but the experience was awful.<p>I&#x27;m pretty well convinced that the emperor wears no clothes when it comes to Git in general.
评论 #26166586 未加载
评论 #26167745 未加载
crowdhailer超过 4 年前
Submodules aren&#x27;t perfect but we&#x27;ve made use of them in a few projects and one we had a process around them they were useful.
sto_hristo超过 4 年前
My lord, so much hate for them submodules. I&#x27;m actively using them for my project, where i have common components that are shared between other components. Having them as dependencies managed by a build tool is cumbersome as sometimes, purely for the sake of convenience, i need to update some shared component in place and have the changes propagate to other dependents.<p>Had a few mishaps, but those were the result of lack of experience. Overall, my experience with submodules is great. I can imagine what terror awaits those with bigger projects where everyone starts pushing random stuff from all directions.
评论 #26167206 未加载
junon超过 4 年前
Most of the &quot;complaints&quot; here are people misusing submodules or not taking the time to learn how Git itself works.<p>I work with submodules almost daily for dependencies in game engines, OS projects, and even network services. I never have issues.<p>However, that&#x27;s not to say they have a strange set of commands (or lack thereof). I have to touch the .git folder way too often, and that shouldn&#x27;t be the case.<p>Maybe I&#x27;ll write a small cookbook of how to deal with issues, including an &quot;everything is fucked, how do I start over?&quot; section.
Izkata超过 4 年前
Note that the &quot;2009&quot; is quite important, a few things here are solved (though with the usual odd interface if you&#x27;re not used to it).<p>&gt; If that repository also has submodules, then your submodule’s submodules will have to be populated by following the steps below from within your project’s submodule directory (confusing yet?).<p>Now:<p><pre><code> git clone repo target cd target git submodule update --init --recursive </code></pre> &gt; Unfortunately, this is wrong. Git does not have a built in way to remove submodules.<p>It&#x27;s a two stage process (the first cleans up .git&#x2F;config, the second actually removes the code and submodule), but does exist now:<p><pre><code> git deinit lib&#x2F;billboard git rm lib&#x2F;billboard</code></pre>
tigerlily超过 4 年前
I want to use Dear ImGui [1] in a C++ project. Sure I can copy the relevant files into my repo by hand, but my instinct says that is not the way. Git submodule seems like the right tool, but there&#x27;s plenty of comments here advising not to use it. So if not git-submodule, then what is the procedure?<p>I just want to have the external repo as a subfolder in my own repo, updating that subfolder as updates become available.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;ocornut&#x2F;imgui" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ocornut&#x2F;imgui</a>
评论 #26171679 未加载
rubyist5eva超过 4 年前
Git is an insane tool. I&#x27;ve never seen a single command line tool blogged about so much. You don&#x27;t see anything like this with regards to Mercurial or other distributed version control systems(and most of them are just as powerful as git, if not moreso), the documentation is usually enough for these tools.<p>For some reason git is special - it has this ability to be completely opaque to so many people and yet still be deployed almost literally everywhere. I am completely baffled by its ubiquity.<p>Thanks Github, I guess..?
nathell超过 4 年前
Oh yeah, submodules can bite. At my previous job, we tried open-sourcing a part of our monorepo using them, which resulted in a clunky workflow. So we whipped up a syncing bot integrating with GitHub that would propagate changes both ways: <a href="https:&#x2F;&#x2F;github.com&#x2F;WorksHub&#x2F;flow-bot" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;WorksHub&#x2F;flow-bot</a>
40four超过 4 年前
This post should have (2009) appended to it. It&#x27;s not obvious because there is no date on the post, but if you scroll down to comments, they are from 2009.<p>That means these code examples were written in Git v1.6. The current Git release is v 2.30. I haven&#x27;t inspected the commands, but I&#x27;d be willing to bet the interface has changed since then.
1MachineElf超过 4 年前
QMK is only one repository I ever spend time working with, and it has some submodules. I find it annoying that they must be pulled each time I switch branches. Should I look into changing them so that they at least point to a repository on my local machine instead of having to re-download from GitHub each time I want to create a new branch? Is that possible, and does anyone else do it?
zoobab超过 4 年前
Docker hub rails to build an image if you call hit submodules in there. I had the problem with DirtyJTAG Dockerfile, build fine on my laptop, does not build on Dockerhub.<p>I mean submodules were a pain in 2010, they are still a pain in 2021. So much for &#x27;open source&#x27;.
dboreham超过 4 年前
Yes submodules are to be avoided, the 99% of the problem is poor documentation that fails to explain submodule behavior adequately, leading the reader to assume the feature conforms to a mental model that it doesn&#x27;t.
评论 #26165833 未加载
juangacovas超过 4 年前
Anyone can compare the &quot;externals&quot; in SVN with &quot;submodules&quot; in git? I&#x27;m curious since I&#x27;m used to externals in SVN and they&#x27;re ok but as always you have to keep some things in mind
评论 #26171546 未加载
matheusmoreira超过 4 年前
I really hate how submodules are just pointers to specific commits. This forces an update to the superproject every time I update the submodule. Even if I add commits to the submodule, it won&#x27;t check out the changes until the superproject&#x27;s pointer is updated.<p>I just like to develop libraries and the application that uses them at the same time. Whenever I change the library, I want to see the changes in the application immediately.<p>The only tool I&#x27;ve used that got this right is Python&#x27;s setuptools. It&#x27;s got a development mode which essentially replaces the package with a symbolic link to a local repository. Why doesn&#x27;t git support this?
newusertoday超过 4 年前
Android combines multiple git repositories with manifest(xml file) and has associated tooling for it. Not sure why that approach is not popular?
tpoacher超过 4 年前
Sometimes I almost feel like git is slowly trying to reinvent svn ...
krona超过 4 年前
Git submodule should be renamed &#x27;git conway&#x27;, named after Conway&#x27;s Law: there is no good reason to use it except within those companies that have to compensate for dysfunctional technical leadership.
评论 #26166150 未加载