Reputation: 1864
In my git repo, the application is located in the root folder, like
.gitignore
pom.xml
data/
src/
README.md
...
due to a redesign of the application (one part is to introduce a parent pom), it i want to move everything into a subfolder, e.g. called system, and then create a second folder (e.g. called api):
system/
.gitignore
pom.xml
data/
src/
README.md
...
api/
src
...
...
What is the best way to move everything to system
? Is git mv for each file/directory in the root directory enough?
Upvotes: 5
Views: 4638
Reputation: 506
To improve on a Markus and tlehman's anser to make it work with sub directoris I made this Where you move everythign to a folder called "subdir"
git ls-files | \
for f in $(cat -); do
mkdir -p $(dirname "subdir/$f")
git mv "$f" "subdir/$f"
done
Then run
git clean -fd
to remove the old directory entries.
Hint: in Zsh you can span multiple lines with alt + enter. Bash doesn't seem to have an equivalent. (I guess you can end the line with ;\
and you can add more commands)
Upvotes: 0
Reputation: 574
In my case the solution described in this gist worked for me (and it keeps the subdirectory structure of the moved folders): https://gist.github.com/ajaegers/2a8d8cbf51e49bcb17d5
The relevant command is: for file in $(ls | grep -v 'system'); do git mv $file system; done;
Upvotes: 0
Reputation: 19015
Simply move everything (except for the .git
directory) into the new folder, run git add --all
, and commit.
Upvotes: 1
Reputation: 5167
I would start by using git ls-files
to get all the files tracked by git, and then loop over them, moving each one to the new system/
directory:
git ls-files | for f in $(cat -); do git mv $f system; done
Upvotes: 0