What I want to do.
All files in my repo are in one folder, but this folder contains other files excluded by .gitignore. I want to reorganise (programmatically) those files from the repo only (and not those ignored) to different folders according to their extensions.
Example..
Let's say I have a folder /project with:
a.py,b.py, c.py, 1.png, 2.png, 3.png
where
- a.py, b.py, 1.png, 2.png are in the git repo;
- c.py, 3.png are not in the git repo, i.e. they are ignored according to the rules in .gitignore.
In the end I want to have two subfolders:
- /project/scripts containing a.py and b.py;
- /project/images containing 1.png and 2.png;
while
- /project still contains c.py and 3.png.
Some ideas.
I read the documentation of the git mv command, but I did not see that I could filter files directly from the git mv command.
One idea is to list those files from the repo using git ls-files, then pipe that to git mv. But I am suspecting that this is as bad as piping ls and mv.
As a last resort, I could use a for loop, but I am sure someone out there knows better. In fact, I am not sure that this would circumvent the issues of piping ls with mv.
Format of filenames.
The filenames are not particularly exotic: apart from their extensions (.py, .png), they only contain alphanumeric characters [a-zA-Z0-9], hyphens -, and underscores _. So piping git ls-files with git mv is perhaps not the end of the world.