Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

branch

merge

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?

like image 816
Tim Trinidad Avatar asked Jan 16 '13 03:01

Tim Trinidad


People also ask

What happens when you merge two branches git?

Merging is Git's way of putting a forked history back together again. The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch. Note that all of the commands presented below merge into the current branch.

What happens when two branches are merged?

Merging Branches. Once you've completed work on your branch, it is time to merge it into the main branch. Merging takes your branch changes and implements them into the main branch. Depending on the commit history, Git performs merges two ways: fast-forward and three-way merge.

How do I compare the differences between two branches in github?

On the Github, go to the Source view of your project. You will see a link named 'Branch List'. Once the page opens you can see a list of all the remote branches. Hit on the Compare button in front of any of the available branches to see the difference between two branches.


1 Answers

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
like image 167
nishantjr Avatar answered Nov 06 '22 23:11

nishantjr