M
M
mmvds2020-08-23 02:20:30
git
mmvds, 2020-08-23 02:20:30

How to remove commit history for only one file in a repository?

The repository has a database dump (several tens of MB), every day at one in the morning, automatic dump creation and git add and git push of all changed data are configured, incl. the base dump is filled in, which is convenient as an additional backup, but unfortunately, git does not handle changes to binary data, which is a dump, and as a result, in a few months .git/objects/pack has grown a lot (several GB)

The question is how to remove everything from the commit history commits for this particular dump.db file other than the last one? At the same time, I would like to keep the commit history of the remaining files

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Aetae, 2020-08-23
@mmvds

This can only be done by completely rewriting the entire history: all hashes in all commits and in all branches will be changed . All developers will need to re-check out all the necessary branches.
If that doesn't scare you, then:

git filter-branch --index-filter "git rm --cached --ignore-unmatch файл" HEAD

In the future, it is better not to store the file in the version control system.
If you really want to - come up with a workaround. For example (offhand) use git submodules for the file and store it in a separate project, in which, with each update, it is stupid to delete the previous branch and create a new one. In the main project, add a hook that will check out this submodule from scratch each time.

I
Ivan Shumov, 2020-08-23
@inoise

No way. Generally. A commit is a change in the state of the entire repository. The concepts of files are rather abstract there.

S
Sergey delphinpro, 2020-08-23
@delphinpro

You can only completely delete a file from history.
Option: How to remove a file from the commit history in GIT?
And then upload the latest version again.
I didn't do that, I don't know how true.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question