Git子模块更新被覆盖 [英] Git submodule update overwritten

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

问题描述

我正在和几个人一起做一个git项目,我们已经包含了一个外部库作为git子模块.我们共享一个普通的遥控器,我们定期将其推入并拉出.

I'm working on a git project with several people and we have included an external library as a git submodule. We share a common remote that we regularly push to and pull from.

自从我们第一次添加此子模块以来,它进行了一些更改,因此我做了git submodule update --remote将其更新为最新版本.这对我有用,我将其推送到我们的共享遥控器.存储提交参考的子模块位置的文件已更改:

Since we first added this submodule there were some changes in it, so I did a git submodule update --remote to update it to the newest version. That worked for me and I pushed this to our shared remote. The file at the location of the submodule where the reference to the commit is stored, has changed:

-Subproject commit <old-commit-hash>
+Subproject commit <new-commit-hash>

当我的同事从我们的共享远程设备中拉出更改时,他们也收到了更改后的子模块,但是,这似乎与常规文件中的更改有所不同,因为它不会覆盖旧版本(我所期望的),但是当他们运行git status时会显示为更改:

When my colleagues are pulling changes from our shared remote, they also receive the changed submodule, however this seems to be different from a change in a regular file, since it does not overwrite the old version (what I would expect), but it appears as change when they run git status:

Changes not staged for commit:
    modified:   src/submodule (new commits)

因此下面的文件已更改(更改为我推送的新修订版),但是git某种程度上认为我同事的本地版本是较新的.但是,这实际上是旧版本,指向我的同事仍在进行的先前修订.

So the file underneath changed (to the new revision that I pushed), but somehow git thinks that the local version of my colleague is newer. However, this is actually the old one, pointing to the previous revision that my colleagues still have.

现在,我喜欢我的同事,但有时他们并没有真正注意,他们所做的只是git add .git commit -a,其中包括 all 更改,并且当然会覆盖对子模块并引用了旧的子模块commit.

Now, I like my colleagues, but sometimes they don't really pay attention and all they do is git add . or git commit -a which includes all changes and of course overwrites the changes to the submodule with the reference to the old submodule commit.

是否有一种方法可以对从此遥控器拉出的所有人员强制执行此子模块更新?可以将此子模块参考文件视为只是正常更新的普通文件吗? 还是我必须告诉我的同事更多的注意力,并不时做一个git submodule update?

Is there a way to enforce this submodule update for all people that pull from this remote? Can this submodule reference file be treated like a normal file that is just updated normally? Or do I have to tell my colleagues to pay more attention and do a git submodule update from time to time?

我希望我的问题清楚.如果没有,请询​​问,我会尽力澄清.

I hope my question is clear. If not, please ask and I'll try to clarify.

推荐答案

对此没有直接解决方案,因为在拉动之后,您需要进行子模块更新.解决此问题的一件事是,您可以创建和分发一个既可以拉动子模块又可以更新子模块的别名,例如:

There's not a direct solution to this as after a pull you need to do a submodule update. One thing you can do to combat this issue is you can create and distribute an alias that both pull and does the submodule update for example:

git config alias.pullAndUpdate '!git pull && git submodule update'

使用该别名将在一个命令中而不是两个命令中从远程子模块中提取更新子模块.

Using this alias will both pull from the remote and update submodules in one command instead of two.

这篇关于Git子模块更新被覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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