同步本地仓库以清除任何本地子模块,这些子模块不在远程仓库中。

huangapple go评论48阅读模式
英文:

How to sync a local repo so that any local submodules which aren't in remote are wiped?

问题

这些是我要返回的翻译部分:

假设你有一个本地仓库,并且想要它与远程仓库中的最后一次提交完全一致。

以下是我为了实现这一目标输入的步骤:

cd <主仓库>
git clean -fxd(清除所有未被跟踪的文件,不包括子模块)
git submodule foreach git clean -fxd(清除所有子模块中的未被跟踪的文件)
git reset --hard(清除主仓库中所有未提交的更改)
git submodule foreach git reset --hard(清除所有子模块中的未提交的更改)

git submodule update --init --recursive(使用远程仓库上的子模块更新所有子模块)

问题在于这些步骤不会删除本地仓库中多余的子模块,这些子模块在远程仓库中不存在。希望对改进步骤的任何帮助将不胜感激。

英文:

Let's say you have a local repo and want it to be exactly as the last commit in your remote repo.

These are the steps that I'm typing in order to achieve this:

cd &lt;main repo&gt;
git clean -fxd       (clean all untracked files that aren&#39;t submodules)
git submodule foreach git clean -fxd     (clean all untracked files in submodules)
git reset --hard             (clean all uncommited changes in our main repo)
git submodule foreach git reset --hard    (clean all uncommited changes in submodules)

git submodule update --init --recursive         (update all submodules with one on remote repo)

The problem is that these won't delete any extra submodules that are in my local repo but not in the remote repo.

Any help in improving my series of steps would be greatly appreciated.

答案1

得分: 2

文档中:

> 如果 Git 配置变量 clean.requireForce 未设置为
> false,则 git clean 将拒绝删除文件或目录,除非
> 提供 -f-iGit 将拒绝修改未跟踪的嵌套 git
> 子目录的存储库(具有 .git 子目录的目录),除非提供第二个 -f
> is given.

因此,使用 git clean -dffx

英文:

From the docs:

> If the Git configuration variable clean.requireForce is not set to
> false, git clean will refuse to delete files or directories unless
> given -f or -i. Git will refuse to modify untracked nested git
> repositories (directories with a .git subdirectory) unless a second -f
> is given.

so git clean -dffx

huangapple
  • 本文由 发表于 2023年5月14日 13:08:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76245912.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定