Question is mostly explained in the title. One of my repository contains a lot of binary files that never really change. However, I changed the format I was using for a new file extension/storage format. Now I've 1000, or so, files sitting in my git history that have no use for (since the data itself hasn't changed, just the storage format). Since they are all of the same extension, I figured it should be an easy way to purge them all, but I have no idea how.
Asked
Active
Viewed 952 times
1
-
1Do you want to remove all of these files completely or just stop tracking them? – Arkadiusz Drabczyk Sep 20 '19 at 09:38
-
Completely. I'm using a self hosted solution, so I don't want to be using up the storage space. – Laz Sep 20 '19 at 10:32
-
1See this [answer](https://stackoverflow.com/a/8741530/3486675) to the question above and replace `path/to/mylarge_50mb_file` with `**/*.ext` where `ext` is the extension of the files that you want to delete. – D Malan Sep 20 '19 at 11:00
1 Answers
0
I'm still not sure I understood your question correctly. You shouldn't remove nothing from the git history. Even if it's
technically possible it's usually not a good practice especially if
you already pushed your branch to the remote repository and shared it
with others as it modifies SHA-1 of commits that other users might
already pulled. All you should do right now is just to remove all
files with a given extension, .x
in this example:
$ git rm "*.x"
rm 'a/a.x'
rm 'b/c/d/e/g/another.x'
rm 'c.x'
It will remove all tracked files that end with *.x
and add them to the staging area:
$ git diff --cached
diff --git a/a/a.x b/a/a.x
deleted file mode 100644
index e69de29..0000000
diff --git a/b/c/d/e/g/another.x b/b/c/d/e/g/another.x
deleted file mode 100644
index e69de29..0000000
diff --git a/c.x b/c.x
deleted file mode 100644
index e69de29..0000000
You will just have to commit them.
Notice you have to put *.x
in double quotes as your shell will
expand *
before running git command.

Arkadiusz Drabczyk
- 11,227
- 2
- 25
- 38
-
this does not answer the question appropriately and there are reasons at times to remove old objects from the commit history – ark Jul 25 '23 at 18:20
-
Would you mind expanding your comment or is it everything we hear from you? – Arkadiusz Drabczyk Jul 25 '23 at 18:23