Home > OS >  How to remove all but the unversioned git files from a directory?
How to remove all but the unversioned git files from a directory?

Time:11-12

I wanted to put a lot of files in a repository. However, their size exceeds 10GB. And they are a lot of files. The total storage is around 13gb.

I am thinking of ways to go about this. Now I am thinking of creating a separate repository where I could push the rest of the files. But since there are many files, it would be too tedious to do that manually.

Is there some way to see which files have not been added to git (maybe they are called unversioned files)? and then remove all but the unadded files. And then init a new repo on the same folder and push the rest to the other repository.

Please let me know if this is possible. I am open to using shell or a python wrapper around git if that exists.

The files are unrelated to each other so it's not a big deal that they would be saved in two separate repositories.

CodePudding user response:

To find files that haven't been committed:

git status --porcelain --untracked-files --ignored

This will show you all file paths with changes, including those in .gitignore, and descending into directories. If you have no pending changes in your repo, this should only be untracked/ignored files. There will be 3 chars at the beginning of the lines like ?? or !! representing the status that you can strip off with | cut -c 4- unless you want to parse them to distinguish different statuses.

From there - it would be easier to move these files to a different directory (rather than moving all the other files).

CodePudding user response:

List all tracked files:

git ls-tree --full-tree -r --name-only HEAD

Remove all tracked files:

git ls-tree --full-tree -r --name-only HEAD |
  xargs git rm
  • Related