How can I remove the history of one file in git, leaving only the most recent version?

StackOverflow https://stackoverflow.com/questions/16221152

  •  13-04-2022
  •  | 
  •  

문제

I have a large binary file in a git repository, which has been changed in a few commits. These commits also included changes to other files. I would like to have only the most recent version of the binary file in the repository, but would like to keep the history of the other files that were changed in these commits.

All of the commits in question have already been pushed to github, and pulled from their by other members of the team.

How can I do this?

EDIT: I don't believe this is a duplicate of the other referenced question. As noted in the comments below, I've looked at that question, but want to remove every version of the file except the most recent one. This criteria is not addressed in the answers to the other question.

도움이 되었습니까?

해결책

The simplest way is to use The BFG Repo-Cleaner, a faster, simpler alternative to git-filter-branch designed specifically for removing large files from Git repos.

You should follow the usage instructions carefully, but the main step is just this - download the Java jar (requires Java 7 or above) and run this command:

$ java -jar bfg.jar  --strip-blobs-bigger-than 100MB  my-repo.git

Any blob over 100MB in size will be totally removed from your repository's history - unless it is the version present in the file tree of your latest commit, so your latest version will be untouched, as you required.

The BFG is also 10-50x faster than git-filter-branch.

Full disclosure: I'm the author of the BFG Repo-Cleaner.

다른 팁

Rather than trying to filter all but the latest version, just nuke the file from the history of your repo and re-add the most recent version:

Consider not tracking this file. Git isn't meant for large binary blobs.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top