0

Can anyone guide me on how to move a git directory into a subdirectory?

The current directory structure is as follows:

/bigproject
  --.git
  --partA/
  --partB/

I want to make it like:

/bigproject
  --partA/
    --.git
  --partB/

I do not care about the history of partB, I will make a new git directory in there. I do want the history for partA kept when I move it into the partA directory.

How would I accomplish this? This guide tries to accomplish something similar but different: Detach (move) subdirectory into separate Git repository

Community
  • 1
  • 1
NoviceCoding
  • 6,145
  • 2
  • 27
  • 33
  • What is wrong with the answer you posted along with your question? This seems to solve your exact problem. – Michael Mior Jul 23 '12 at 13:06
  • Thats more concerned with splitting directories and keeping things. Perhaps git-paranoia was getting to me. – NoviceCoding Jul 23 '12 at 13:14
  • I don't really understand your question then. It sounds like you want to split directories and keep things. Anyway, looks like you found your answer :) – Michael Mior Jul 23 '12 at 18:20

1 Answers1

1
git rm -r partB
git mv partA/* .
git commit

... and you're done.

This keeps all your previous history (you could rewrite it with git filter-branch to get rid of partB's history and the partA grand rename if you wish) but makes the current partA directory be the new top of the repository.

Borealid
  • 95,191
  • 9
  • 106
  • 122
  • Is there an issue with this and ignored files? I'm getting fatal: not under version control, source=bp-site/manage.pyc, destination=manage.pyc – NoviceCoding Jul 23 '12 at 12:51
  • @NoviceCoding Yes. You can remove ignored files from `partA` using git's `clean` command, or move them the old-fashioned way. – Borealid Jul 23 '12 at 12:54