How do I move my git repo down level in the directory tree?
I'm currently writing an app in C# using using Visual Studio. As such, VS2010 created a Solution directory with my project directories inside. So my Hierarchy is like this:
Solution
.git
project1
project2
What I'd like to do is make it like this:
Solution
Project 1
.git
Project 2
As of right now the files in the solution are tracked, except for the project 2 (so stuff like project.sln for exam开发者_运维问答ple). Is there a way I can do this without rewriting the history?
Thanks in advance.
This was actually by SethRobinson on #git@freenode.net but here was his solution:
Step one, move the entire git tree into the subdirectory:
mkdir .solution;
mv Solution .solution/Project1;
mv .solution Solution;
mkdir Solution/Project2
Step two, tell git to promote the subdirectory into the root:
cd Project1;
mkdir .foo;
mv * .foo;
cd .foo;
mv Project1/* ..;
cd ..;
rm -rf .foo;
git add -A .;
git commit -a -m "Promoted Project1 to root"
If I understand correctly, the tracked files in your repository currently consist of files and directories, all within the "project1" subdirectory. Since everything is withing the project1 subdirectory, you'd essentially just like to start your repository there. Is that correct?
If that's true, then you cannot do that without either (1) rewriting your project history (something git filter-branch
can help you with), or (2) adding history by adding a commit that moves all the files.
Basically, you can't retroactively change things without changing the commit IDs; this is a feature of git. But your situation is addressable. Just let us know which option your prefer, and we'd be glad to help.
if project 2 is not tracked at all, i think you'd just be able to move it to where you want it. git tracks changes to content separate from the tree structure so it will see the files as just moved around, but no content change.
git filter-branch --subdirectory-filter Project\ 1 HEAD
This does adjust history though.
I tested it like so:
root/
.git
folder/
index
git filter-branch --subdirectory-filter folder HEAD
And got:
root/
.git
index
精彩评论