0

In git bash I can use git mv home/subdir_1/my_submod home/subdir_2/my_submod to move a submodule between directories. Git handles changing .gitmodules and stages the change to be committed.

Is there a way to do this cleanly with magit? I've tried using R in dired and then staging things in magit but magit runs into an error where it's looking for the original directory and can't find it since its been renamed.

I've checked the submodule transient docs but I don't see anything related to moving the submodule.

thanks for all suggestions/solutions.

1

It helps to remember that a submodule is just a regular file to the parent repo.

I was able to do this using magit-file-rename.

The magit-process buffer shows the actual git actions performed

The test sequence was:

  • magit-submodule-add
  0 git … submodule add --name extern/hugo-debugprint --force -- https\://github.com/kaushalmodi/hugo-debugprint.git extern/hugo-debugprint
Cloning into '/tmp/testrepo/extern/hugo-debugprint'...
remote: Compressing objects: 100% (5/5), done.        
Resolving deltas: 100% (68/68), done.

  0 git … submodule absorbgitdirs extern/hugo-debugprint
  0 git … commit --
hint: Waiting for your editor to close the file...
Waiting for Emacs...
[master 547557c] [add test submodule]
 2 files changed, 4 insertions(+)
 create mode 100644 .gitmodules
 create mode 160000 extern/hugo-debugprint
  • magit-file-rename
  0 git … mv /tmp/testrepo/extern/hugo-debugprint /tmp/testrepo/extern/debugprint
  0 git … commit --
hint: Waiting for your editor to close the file...
Waiting for Emacs...
[master a6ce6d4] [moved submodule]
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename extern/{hugo-debugprint => debugprint} (100%)
| improve this answer | |
  • I see, thanks. As a note magit-file-rename can be called from the magit buffer with R – Hugh_Kelley Aug 4 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.