It has been shortened as it contains a lot of similar lines. The following is example output from the above command. In case the filters result in an empty commit, this causes the complete commit to be removed.Įxecuting the above command may take a while depending on the size and amount of commits in the repository. Providing “–prune-empty”, instructs git filter-branch to remove empty commits completely. As the tag itself shall not be modified but just re-committed with reference to the modified commit, the “cat” command in this filter returns the tag name just as it received it – therefore not modifying it. It will be executed for each tag pointing to a rewritten commit. Shell wild-cards could be used here to remove a number of files at once.Īnother filter is applied via “–tag-name-filter”. The last argument is the file/directory name to be removed. This is needed for the git filter-branch to continue in case the commit does not contain any matching files. The argument “–cached” causes the files to be removed from the index, while “–ignore-unmatch” causes git always to exit with return code 0. It instructs git to remove the files specified by the last argument. This filter command itself is also a git command. The filter command used in the above command is “git rm –cached –ignore-unmatch directory/and/filename.extension” With “–index-filter”, the repository’s index is filtered. In the above command, “–all” is specified after the “–” option which separates the rev-list from the “filter-branch” options. This filter is run for all branches specified (rev-list). The “filter-branch” allows to rewrite the git history by executing a filter for every commit. 'git rm -cached -ignore-unmatch directory/and/filename.extension' \ $ git filter-branch -force -index-filter \ The following command can be used to remove the file “directory/and/filename.extension” from the entire repository. The different filters allow modifying different parts of the commit. For each commit, filters are applied after which the changes are re-committed. Rewriting the history is done with “ git filter-branch” by walking through the complete history. With this in mind, make sure to start with a clean repository. When reaching deep into the repository’s history like described here, starting from a clean state reduces the risk of something going wrong.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |