1

I have two similar programs(with almost same file hierarchy) with some differences and both are separate bitbucket repository. I have added some feature in the first program and wondering of using its commits to reproduce the same feature in the second program?

It maybe a silly idea as programs are separate, but I am thinking that way because the files I have modified have exactly the same hierarchy in both the repositories. Is it feasible to do anything like that? Or I have to manually copy/paste the changes...

UPDATE:

As suggested in comment by Enrico Campidoglio, one of the solution approach for this can be by using diff and format-patch mentioned here: Create patch or diff file from git repository and apply it to another different git repository

DonBaka
  • 325
  • 2
  • 14
  • take a look at this, might be useful - https://stackoverflow.com/questions/37471740/how-to-copy-commits-from-one-git-repo-to-another – iatharva Aug 30 '21 at 12:10
  • 1
    @iatharva looks like it is not the same scenario, there the problem is related to two repo for the same program unlike here – DonBaka Aug 30 '21 at 12:45
  • Okay, my bad (I missed that) – iatharva Aug 30 '21 at 12:46
  • Does this answer your question? [Create patch or diff file from git repository and apply it to another different git repository](https://stackoverflow.com/questions/28192623/create-patch-or-diff-file-from-git-repository-and-apply-it-to-another-different) – Enrico Campidoglio Aug 30 '21 at 12:54
  • @EnricoCampidoglio Yes, that is correct. But if you look closely, my question emphasis on the general solution approach for merging changes in two different programs and the other question is straightforward asking for the working of `diff` and `format-patch`. Although I totally agree with you... – DonBaka Aug 30 '21 at 15:44
  • @EnricoCampidoglio I used the `format-patch` and it is working fine. Is there a way to patch say `diff.patch` in a single commit history instead of logging all the commits used during creation of patch? – DonBaka Aug 31 '21 at 09:37

1 Answers1

1

You should export each single commit by:

git format-patch -{NUMBER_OF_BACKWARD_COMMITS} {STARTING_COMMIT_HASH} --stdout > diff.patch

Then apply the patch generated file on the other repository by:

git am < diff.path.

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
  • can you explain those two arguments `NUMBER_OF_BACKWARD_COMMITS` and `STARTING_COMMIT_HASH`? I have a consecutive list of commits to apply to another repo... – DonBaka Aug 30 '21 at 15:39
  • You have to write down the hash of the last commit you want to export (STARTING_COMMIT_HASH) and how many commit before this you want to include (NUMBER_OF_BACKWARD_COMMITS). – Antonio Petricca Aug 30 '21 at 16:25
  • I used the `format-patch` and it is working fine. Is there a way to patch the `diff.patch` in a single commit history instead of logging all the commits used during creation of patch? – DonBaka Aug 31 '21 at 09:34
  • If I remember, you should remove `--stdout > diff.patch` in order to get a singole patch file for each commit of the history you selected. – Antonio Petricca Aug 31 '21 at 09:46