合并两个 git 分支之间的差异并将其应用于工作副本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14350930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:01:22  来源:igfitidea点击:

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

gitmergebranch

提问by Tim Trinidad

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.

我有一个开发存储库和一个部署存储库。部署代码时,代码库从 dev 中检出,rsync 到部署工作副本,并提交到部署存储库。因此,这些存储库是独立的,但相似。

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 命令是:

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

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

... 其中 deploy_dir 甚至不需要是工作副本。

Is this possible?

这可能吗?

回答by nishantjr

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

一种方法是从另一个 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