如何告诉 Git 我已经更改了子模块的路径?

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

How to tell git that I already changed the path of a submodule?

问题

我在以下路径有一个子模块:src/level_1/level_2/my_Submodule

在 VS Code 中,我将路径更改为:src/level_1/level_2/level_3/my_Submodule

在这种情况下,git 给我一个错误,提示 "未找到 my_Submodule 的路径"。

我如何让 git 使用我已经修改的新路径?

我不能使用 git mv old_path new_path,因为我必须从 vscode 内部更改路径,这样 vscode 可以更新导入,以避免破损的路径。

我已经阅读了 stackoverflow 中所有类似的问题,但没有一个解决我上面解释的情况。

英文:

I have a submodule at the following path: src/level_1/level_2/my_Submodule.

In VS Code, I changed the path to: src/level_1/level_2/level_3/my_Submodule.

In this case, git gives me an error that the "path to the my_Submodule is not found".

How can I make git to use the new path that I already modified?

I can't use git mv old_path new_path because I have to change the path from inside vscode itself, so vscode can update the imports, so I won't have broken paths.

I already read all the similar questions in stackoverflow and none of them solves the situation I explained above.

答案1

得分: 0

  1. 你至少有两种选择(我认为):

  2. 前往更新 git 文件自己,将旧路径替换为新路径:存储库的 .submodules 文件,.git/config 文件,以及其他一些你可以通过 cd.git 文件夹并使用类似 grep 的工具进行文件内容搜索(如 .git/modules/<previous path>/config)来找到的文件。

英文:

You have at least two options (I think):

  1. Since you want to do the move in VS Code to use it's auto-update-import-path feature, just do the move with VS Code to use that feature, then undo the move outside of VS Code (ex. with the mv unix command), and then take the normal route of doing things stated in the answers to https://stackoverflow.com/q/4604486/11107541 (git mv old/submod new/submod).

  2. Go and update the git files yourself, replacing the previous path with the new path: The repo's .submodules file, .git/config file, and several others you can find by cding into the .git folder and doing a file-content search (with a tool like grep) for the previous path, such as .git/modules/&lt;previous path&gt;/config.

huangapple
  • 本文由 发表于 2023年2月26日 22:23:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75572625.html
匿名

发表评论

匿名网友

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

确定