Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I move all git content one-level up in the folder hierarchy?

Tags:

git

directory

I have a git repository whose structure looks like:

+--repo.git | +----+bootstrap.py +----+buildout.cfg +----+.gitignore +----+webapp | +---------+manage.py +---------+modules +---------+templates +---------+static +---------+... +---------+... 

I would like to move the contents of the webapp folder one level up. My resulting repo should look like:

+--repo.git | +----+bootstrap.py +----+buildout.cfg +----+.gitignore +----+manage.py +----+modules +----+templates +----+static +----+... +----+... 

Can I do this by simply moving all the files of the webapp directory one level up, deleting the empty webapp directory and then committing the changes? Would this preserve the commit history of the files under the webapp directory?

Although a very simple question for many of you, I'd like to be sure. The last thing I'd want is a git soup.


I tried moving the files but I lost the commit history as git doesn't really handle a move or a rename. I do know that even though it shows up as a new file in the logs, it is still possible to view the commit history for the file using some options in git log.

From what I've read, the best way to accomplish this would be using git-filter. I'm not very good with shell or git so could someone tell me what I'd need to execute to do the aforementioned.

like image 673
Mridang Agarwalla Avatar asked Aug 20 '11 09:08

Mridang Agarwalla


People also ask

How do I move up a directory in git?

To change this current working directory, you can use the "cd" command (where "cd" stands for "change directory"). For example, to move one directory upwards (into the current folder's parent folder), you can just call: $ cd ..

How do I move a folder from one level?

To change the order of a file or folder, click the dots on to the left of the folder or file's name that you're interested in. Dragging while clicking will move the file or folder up and down. A gray outline will show you where the file will appear if you drop it at that point.


1 Answers

The right way to do this is:

git mv repo.git/webapp/* repo.git/. git rm repo.git/webapp git add *  git commit -m "Folders moved out of webapp directory :-)" 
like image 116
Sumeet Pareek Avatar answered Sep 20 '22 17:09

Sumeet Pareek