Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between git subtree and git filter-banch

Tags:

git

Is there any difference between these two commands?

git subtree split --prefix=some_subdir -b some_branch

and

git filter-branch --subdirectory-filter some_subdir some_branch

I would like to use git filter-branch instead of git subtree because I also want to delete some files in the new branch, but I am worried that this guarantee, which is true for git subtree, might not be valid for git filter-branch:

Repeated splits of exactly the same history are guaranteed to be identical (ie. to produce the same commit ids). Because of this, if you add new commits and then re-split, the new commits will be attached as commits on top of the history you generated last time, so 'git merge' and friends will work as expected.

like image 889
AndreKR Avatar asked May 19 '13 10:05

AndreKR


1 Answers

filter-branch definitely does not give any such guarantee, so when using it you are definitely on the hoping side. But the subdirectory filter has exactly reproducible results and filter-branch does not touch the commit information (commit and author timestamp and person). As this is the information the commit sha is created from, filter-branch should generate the same history again.

That’s all you going to get as long as filter-branch does not start making any guarantees, and that seems unlikely.

like image 175
Chronial Avatar answered Oct 05 '22 19:10

Chronial