Home > Blockchain >  How do I move my git project to a subdirectory for all commits, except one file?
How do I move my git project to a subdirectory for all commits, except one file?

Time:01-06

I'm trying to move my entire repo root into a sub-directory, for everything except one file.

For example, I have something like:

root
-Folder1
-Folder2
-.gitattributes

And for all commits and history, I want

root
-ProjectA
--Folder1
--Folder2
-.gitattributes

i.e., I want to move everything except .gitattributes to a subdirectory. If I use

 git filter-repo --to-subdirectory-filter ProjectA/

everything gets moved. I can't find the strategy for moving everything except a single file.

How do I keep the file where it is? Or how do I move just that file back up to the root with another command?

CodePudding user response:

If you can, you would list all elements except .gitattributes, and rename them in one command, using path renaming:

git filter-repo --path-rename Folder1:ProjectA/Folder1 \
                --path-rename Folder2:ProjectA/Folder2 \
                ...

The OP House suggests in the comments the more sensible approach:

  • moving everything to a subdir,
  • then moving the .gitattributes back with --path-rename ProjectA/.gitattributes:.gitattributes

I would do each step in a separately cloned repository, to make sure I can go back to the original one if it fails.
The second step would be done in a clone of the repository from the first step.

  •  Tags:  
  • Related