Q:

How to sync Perforce to Git while keeping existing Git commit hashes?

I'm in the process of moving our repository to git. During the transition, engineers will still be submitting to the Perforce repository. While engineers are still working, I'll be switching systems to use the Git repository. As such, I've been doing the following to keep the repositories in sync:
rm -rf family
git clone ssh://git@example.com:7999/project/family.git

cd family
git p4 sync //depot/project/family@all
git rebase remotes/p4/master
git push -f

This works fine, but one of our tools needs the commit hashes to stay the same; the above creates new commits and, therefore, new commit hashes. Is what I need even possible with git-p4 and git? If so, I'm imagining it'll require magic with update-refs, etc and I'm still on the learning curve when it comes to git plumbing commands.

A:

The following works for me:
rm -rf family
git clone ssh://git@example.com:7999/project/family.git

cd family
git update-ref refs/remotes/p4/master $(git log -1 --format='%H')
git symbolic-ref refs/remotes/p4/HEAD refs/remotes/p4/master
git p4 sync //depot/project/family || true
git p4 rebase
git push

