Basically, I needed to move some repo's around and several of the repo's have submodules. I have edited my .gitmodule file to change the origins to the new location, however, it appears that checking out a previous commit will get the old origins. I'd like to make it such that all previous commits will appear to have the new .gitmodule file. Is there a procedure for rewriting the history for one file for all time?
Asked
Active
Viewed 39 times
1
-
1Rewriting your whole history for that seems a bit heavy handed. Would [insteadof](https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtinsteadOf) cover your need? Otherwise there are existing questions/answers for replace in all git history' (like [this one](https://stackoverflow.com/q/19905409/761202) or similar). – AD7six Apr 12 '23 at 16:55
-
2"it appears that checking out a previous commit will get the old origins" I think this is a flawed assumption. AFAIU .gitmodules sets up the submodule mapping when and only when you run `git submodule init` or a similar command. If you reconfigure the submodule origin (but don't rewrite history) old commits should check out from the new submodule origin when you `git submodule update` – nmr Apr 12 '23 at 16:57
-
nmr, Part of the issue would be a command like git submodule sync --recursive after checking out to a previous commit. This will cause the urls to update to the old locations. There may be other examples too, but that was the one that I was thinking of. – Rich Maes Apr 12 '23 at 17:15
-
You've got a point there. I didn't know about `git submodule sync`, and I can see the appeal of it. It's worth noting that you can also just use `git submodule update` instead of sync, and that sidesteps your stated problem. The deleted ChatGPT answer is fairly close to the the history rewrite you seek, so might be worth a shot if you're not interested in changing the git commands used to deal with submodules. Rewriting history is a hell of a hammer though, and will essentially SNAFU other users of the repo. – nmr Apr 12 '23 at 19:50