4

We have a Perforce repository and we later switched to Git. Still we have a release branch that is in perforce and now, I need to apply some of the git commits to the perforce branch.

According to what I have read, it seems this can be done by doing a git diff, creating a patch and then applying to the perforce code base. But, I have seen any concrete example. Could anyone help me on this? Thanks.

1 Answers1

6

You can form a patch from git history with a simple git diff <point1>..<point2> > the_diff.patch and then apply that patch to your working tree using patch -p1 <the_diff.patch and commit the changes to perforce.

Also you could form a sequence of git commits as separate patch files using git format-patch <point1>..<point2> and apply them sequentally if you wish.

There's git-p4 tool to import/export commits from/to git and perforce repositories, but I haven't use it so far.

For Windows users who do not have git installed (well, I do suggest to install it anyway :-)), one can use Patch for Windows or install MSYS2 bundle which contains the utility.

Alternatively one can try to apply patches using their favorite IDE.

user3159253
  • 16,836
  • 3
  • 30
  • 56
  • Is the `patch` command a unix dependency? If so, any suggestions for other platforms? – ojchase Jun 13 '23 at 18:40
  • patch is a rather portable tool. What platform do you use? – user3159253 Jun 14 '23 at 21:05
  • I'm really just trying to help [How to send changes from a git commit to a non-git user?](https://stackoverflow.com/questions/76467697/how-to-send-changes-from-a-git-commit-to-a-non-git-user) which got closed as a duplicate of this question. They appear to be on Windows. – ojchase Jun 14 '23 at 21:15
  • 1
    I have updated the answer. Feel free to make necessary corrections too because I'm not a Windows user with a fresh hands-on experience. – user3159253 Jun 19 '23 at 07:37