Search code examples
gitmv

Git move files accross submodules


I have a repo A that uses a submodule B. Repo A has file file.filetype as a tracked object. I want to move that file to B. I don't necessarily want to keep the history, but I want to be very clear for any user of B that the file wasn't just newly created, but rather moved from A (e.g. by providing the URL to A and the revision where the file was moved away). Similarly on A, I want it to be explicit as to what happened : at this revision, the file was moved to B where it could be found starting at some revision.

I tried git mv, and it seems to have worked, but now on A, git status also tells me that B has been deleted, and that some (if not all) of the files of B are considered "untracked files", which not only strange but also worrisome. Inside B however everything is more or less fine - it notes the apparition of a new and therefore untracked file. It doesn't know where it came from sadly, but it has seen it.

Any suggestion ?


Solution

  • Cancel the git mv (git reset HEAD), and run the actions manually :

    • move the file on your disk from A to B using mv
    • from submodule B : add file & commit, with a message which mentions the information you want : "file imported from repo A (commitid-in-A)"
    • fome repo A : commit both the file removal, and the new state of submodule B, with a commit message which mentions the information you want : "file moved to B (commit-id-in-B)"