Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Git, how to squash all commits related to a file or folder?

Tags:

git

How to squash all commits related to a specific file or folder? I can probably collect the hashes in a first step, and then pipe them as input to a second command.

It would also be acceptable to modify commits in order to remove the parts related to specific files or folders, with all recent changes there being committed by a new, single commit.

To make the use case clearer, let us say that i want to eliminate the history related to specific files

like image 588
danza Avatar asked Sep 28 '22 13:09

danza


1 Answers

You may want to use git filter-branch, like this :

git filter-branch --tree-filter 'rm -rf FOLDERNAME' HEAD

More info here : http://git-scm.com/docs/git-filter-branch

Be really careful with this command, this it's rewriting the entire history. Be sure to have a backup copy of your repository somewhere.

like image 103
blue112 Avatar answered Oct 02 '22 14:10

blue112