This question took me part of the way, but I'm still missing something.
I have a single-user repository (so no problems with rewriting history vs push/pull) where I have developed product code and support code and documents together.
After a year-or-so's work, I have finally seen the light, and want to split my repo in two. This is what I tried:
- Create two new directories under the project root; let's call them Project/Code/ and Project/Support/
- git mv all the Code stuff into Code/
- git mv all the Support stuff into Support/
- copy and modify .gitignore appropriately
- commit everything
Now, when I run what I thought the right command:
git filter-branch -d /cygdrive/z/temp/ --subdirectory-filter Code/ -- --all
I just get a detached branch with a single commit, my original branch is still there (as original/refs/head/brent
), and all the other branches are as they were.
What I really need is something to rewrite history as if the Code/ directory was "always there", and the Support/ stuff wasn't, and vice versa for the other side.
I'm a relative Git noob, so I'm sure I've missed some important concept -- please fill me in.
OK, I've done that, and it appears to do what I need very well, for which much thanks. I have a couple of supplementaries:
I added a -r to allow removal of complete directories. Is this correct? The actual command I used was:
git filter-branch --index-filter \
'git rm -r --cached --ignore-unmatch ' \ -- --all- The repository now has about twice as many commits as I expected. These appear in gitk as being chained back from thing with names like "original/refs/heads/TestSys".
I assume that these are the original commit tree; how do I get rid of them? They don't show up in fsck, and neither prune nor gc --aggressive gets rid of them.
开发者_高级运维Uh-oh, just read the fine manual; going to try git clone to prune the cruft.
OK, now I've done the clone, and the repository has shrunk back to its original size. The clone only seemed to copy branch information for the current (source repo) HEAD, and I had to set up the other branches manually with this:
for n in `git branch -r|grep -v 'HEAD'` ; do git branch ${n/origin?/} $n ; done
Is there a simple way to do this at clone time?
Plus this: I don't wish to seem ungrateful, but there are now "empty" commits which used only to touch files that are now gone.
Is there a simple way to eliminate these?
Really grateful for your help and patience.
I suppose moving the files into the subdirectory is the problem – git doesn't follow them before the move. I would suggest cloning two new repositories from the old one and running following in each of them:
git filter-branch --index-filter 'git rm --cached --ignore-unmatch <list of files that shouldnt be here>' -- --all
精彩评论