0

I have a big git repo and I want to split that into 2. I am able to do this using "git filter-branch" or "git subtree split" but both methods are creating completely new commits-ids (SHAs). I know we are rewriting history and it will change commit-ids.

But my requirement needs to have same commit-ids even after splitting repos. Is it possible?

Example:

Have a git repo foo-bar.git with below commits

*foo-bar.git*
1fd3dsg refs #1 change-1 to foo
4sad2as refs #2 change-1 to bar
3edsads refs #3 change-2 to foo
5adsggh refs #4 change-2 to bar

Now we split repo foo-bar.git into foo.git and bar.git. Now foo.git will get all commits made for foo and bar.git will get all commits made for bar, but their commit-ids have changed.

What I got:

*foo.git*
s43dfsa refs #1 change-1 to foo
a234s2f refs #3 change-2 to foo

*bar.git*
1s3ds3q refs #2 change-1 to bar
3re2ef2s refs #4 change-2 to bar

What I am expecting.

*foo.git*
1fd3dsg refs #1 change-1 to foo
3edsads refs #3 change-2 to foo

*bar.git*
4sad2as refs #2 change-1 to bar
5adsggh refs #4 change-2 to bar
Sridhar
  • 803
  • 1
  • 12
  • 21

1 Answers1

5

Changing commit ids is inevitable. These are based on the changes in each commit, the commit message, and the parent commit id.

Because that parent commit id will change when you rearrange the single commits, the commit ids cannot stay the same.

Sven
  • 69,403
  • 10
  • 107
  • 109
  • Yep, it's mathematically impossible (okay, astronomically improbable, which is similar), and this is what you want. Git is a content-addressable storage system, meaning the content you put in becomes its own address. This is why you can trust everything in git to be what it says it is. To be able to change the IDs, aside from being impossible, would also completely destabilize an incredibly robust system, which is the problem with many (most?) other versioners, in which you can *not* rely on the content actually being what it's supposed to be. – Gary Fixler Feb 26 '14 at 02:10
  • Thanks @Sven and GrayFixler.. I knew its not possible. But, to fix one of our experiment failure we found this is the only way, so I wanted to try out of greediness if there is any chance to achieve this.. Thanks for clarification.. – Sridhar Feb 26 '14 at 06:14