Skip to content

fangkangmi/Something-I-learned

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Something-I-learned

User In my git history there's a large dir named LongFormer_parameters, how can I delete it from my git history?

git filter-branch --force --tree-filter 'rm -rf path/to/LongFormer_parameters' --prune-empty --tag-name-filter cat -- --all

Certainly! Let's break down the command git filter-branch --force --tree-filter 'rm -rf path/to/LongFormer_parameters' --prune-empty --tag-name-filter cat -- --all:

  • git filter-branch: This is the main command used to rewrite Git history. It allows you to apply various filters to modify the commit history.

  • --force: This flag forces Git to rewrite the history even if it detects potential problems. Use this flag with caution as it can overwrite existing history.

  • --tree-filter 'rm -rf path/to/LongFormer_parameters': This option specifies the filter to be applied to each commit. In this case, the --tree-filter flag is used, indicating that you want to modify the tree (directory) structure in each commit. The command within the single quotes '...' specifies the action to be performed, which is to remove the directory named LongFormer_parameters using the rm -rf command. Replace path/to/LongFormer_parameters with the actual path to the directory relative to the repository's root directory.

  • --prune-empty: This flag tells Git to remove any empty commits that may result from the filtering process. This ensures that only relevant commits are retained in the history.

  • --tag-name-filter cat: This option specifies how Git should handle tags during the filtering process. In this case, the cat command is used, which essentially preserves the tags as they are without making any changes.

  • -- --all: This double dash (--) is used to separate the filter-branch options from the revision or branch arguments. The --all argument indicates that you want to apply the filter to all branches and tags in your repository.

By running this command, Git will iterate over each commit in your repository, remove the specified directory (LongFormer_parameters in this case) if it exists, and rewrite the history accordingly. The resulting history will no longer contain the directory in question.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published