AndreKR
AndreKR

Reputation: 33678

Difference between git subtree and git filter-banch

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.

Upvotes: 10

Views: 1183

Answers (1)

Chronial
Chronial

Reputation: 70683

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.

Upvotes: 3

Related Questions