Merging diff between two git branches and applying it to working copy

13,168

One way is to fetch the branch from the other repo:

cd <deploy-path>
git remote add devel <devel-path>
git fetch devel

git cherry-pick devel/master...devel/branch  # Assuming your branch is based on master

Another way is to create a patch and then apply it:

git diff commitid1 commitid2 > something.patch
cd deploy
git apply something.patch
Share:
13,168
Tim Trinidad
Author by

Tim Trinidad

Updated on June 19, 2022

Comments

  • Tim Trinidad
    Tim Trinidad almost 2 years

    I have a development repository and a deploy repository. When deploying code, a codebase is checked out of dev, rsync'd to the deploy working copy, and committed to the deploy repository. These repositories are therefore separate, but similar.

    On dev, I have a branch. I would like to "apply" that branch to the deploy working copy. In other words, I would like to replay all commits on the branch (excluding merges) to the deploy repository (in one commit, if possible), or to take a diff between branch and master and apply it to the deploy working copy.

    I think a similar svn command would be:

    svn merge $SVN_REPO/trunk $SVN_REPO/branch/dev_branch deploy_dir
    

    ... where deploy_dir doesn't even need to be a working copy.

    Is this possible?

  • Tim Trinidad
    Tim Trinidad over 11 years
    The diff/patch method worked perfectly, because there were some ancestry anomalies that I wanted to ignore. Since there were some images that were added, I used git diff --binary c1 c2 > something.patch
  • Tim Trinidad
    Tim Trinidad over 11 years
    It's also interesting that there's not a "git merge --ignore-ancestry" or something similar to the svn command above.
  • nishantjr
    nishantjr over 11 years
    @Tim Yeah, merge won't work. You should try cherry-pick instead.
  • Brian Hong
    Brian Hong almost 4 years
    The patch method worked great! I think it is simpler. (but saved to home directory rather than somewhere inside the git directory)
  • hunter_tech
    hunter_tech over 2 years
    Life-saving answer!!