git - switching between branches where a subdirectory was in the main repo vs. submodularized -
we've made subdirectory s separate repo , re-added submodule in branch b. when want switch original branch a, subdirectory checked original repo, git complains stuff submodule untracked , has moved away first. can switch @ without manually dragging s away , moving in b?
update: comments below indicate may deficiency of old branch , git not willing smart thing here. so, , kind of rebasing, if any, of original branch s in main repo can let coexist , checkout-able @ time vs. submodularized version?
your history looks this:
---x \ y b
git ls-tree a
shows (e.g.):
040000 tree 48770cdc854cc14fecc71029180be7a979f4baa1 s 100644 blob beac6e189b7c69b249271b52cd2db5e418c05a50 file
git ls-tree a:s
shows (e.g.):
100644 blob 6357df9903460c9e8b43311aff3c7a6fd7fe6aa1 somefile
git ls-tree b
shows (e.g.):
100644 blob 1f8556335163a2bcbcc366a17d08d1f8e0540e6f .gitmodules 160000 commit 234871cd6f0c1f9109e483383d7712dd8a1986e5 s 100644 blob beac6e189b7c69b249271b52cd2db5e418c05a50 file
(cd s; git ls-tree head)
shows (e.g.):
100644 blob abccc3958be33be4b93f56efae1b60820545aad2 somefile
you want move commit y (or later) commit x (or earlier) or vice versa.
if active branch b, git checkout a
says (e.g.):
error: following untracked working tree files overwritten checkout: s/somefile please move or remove them before can switch branches. aborting
git tries hard never lose data unless tell (e.g. “force” options). problem git finds , reports here branch has different content s/somefile
working tree. because s/somefile
not tracked (from perspective of superproject), git refuses replace file , refuses switch branches/commits.
git arguably smarter (by noticing file tracked in submodule, should not considered untracked when switching branches in superproject), limitation of current implementation. there google summer of code 2011 project git aims address areas of submodule support, not clear me whether exact problem covered.
you could, suggest, rewrite history s
appeared have been submodule. present smoothest surface future commit switches, complicated fact need make sure have commits in submodule’s origin repository reflect each historical state of s
directory in original commits. if have many different s
trees (i.e. had made local changes under s
before converting submodule), may complicated process/script.
a simpler workaround might temporarily checkout “empty branch” in submodule before switching commit has directory.
create “empty branch” in submodule.
git checkout --orphan empty git rm -r --cached . git commit --allow-empty -mempty
you publish “branch” in submodule’s origin repository no 1 else need recreate form themselves.
when need switch commit
s
submodule commits
directory, checkout “empty branch” in submodule first:(cd s && git checkout empty) git checkout
you see warning because git leave behind
s/.git
:warning: unable rmdir s: directory not empty
because
s/.git
still present, should careful issue git commands outsides
when working on commit hass
directory; git commands issued unders
operate ons/.git
(in state, “subrepository”, not full submodule) instead of top level.git
repository.when need switch commit
s
directory commits
submodule, need check out appropriate branch/commit in submodule after switching superproject’s commit.
can usegit submodule update
restore commit recorded in superproject. or, if working on branch in submodule, check out.git checkout b # git submodule update # or checkout specific branch (cd s && git checkout master) # or checkout previous branch (cd s && git checkout -)
Comments
Post a Comment