我怎样才能将一个分支中的特定文件合并到Git中的另一个分支中 [英] How can I merge a specific file from one branch into another branch in Git
问题描述
我在一个git repo中有2个分支,让我们打电话给他们,开发和测试。我在单个文件somecode.js中进行了更改。这两个分支都改变了一些code.js。这两个分支有显着的分歧(但可控),所以直接合并是不够的。
我试过 http://jasonrudolph.com/blog/2009/02/25/git-tip-如何合并特定文件从另一个分支/ /但它不合并两个文件的内容。您基本上只是在文件上写下来,而不是实际合并文件的内容。
我也试过:
git checkout -b newbranch
git checkout测试somecode.js
git commit -m从newbranch更改某些代码
git checkout dev
git merge newbranch
和
git checkout -m test somecode.js
(我真的很有希望与-m合并,但它似乎没有为我工作......)
我以为我接近我所需要的,但后来我意识到它只是快速转发提交意味着它没有合并,它写在测试原始文件。
所以,重申,如何合并一个特定的文件从一个分支到另一个分支,而不是仅仅写入分支中的文件,我正在使用git进行合并。
你喜欢使用
git checkout -p
您的情况
git checkout dev
git checkout -p test somecode.js
您可以交互式应用差异。
I have 2 branches in a git repo, lets call them, dev and test. I have changes in a single file, somecode.js. Both branches have changes to somecode.js. The 2 branches have diverged significantly (but manageably) so a straight "merge" is insufficient.
I have tried http://jasonrudolph.com/blog/2009/02/25/git-tip-how-to-merge-specific-files-from-another-branch/ but it doesn't merge the contents of both files. You basically just write over the file instead of actually merging the contents of the file.
I have also tried:
git checkout -b newbranch
git checkout test somecode.js
git commit -m "somecode changes from newbranch"
git checkout dev
git merge newbranch
And
git checkout -m test somecode.js
(I was really hopeful with the -m for merge, but it didn't appear to work for me...)
I thought I was close to what I needed, but then I realized that it just fast-forwarded the commit meaning it didn't merge, it wrote over the original file in test.
So, to reiterate, how can I merge a specific file from one branch into another branch without just writing over the file in the branch I am merging into using git.
I think you like to use
git checkout -p
In your case
git checkout dev
git checkout -p test somecode.js
And you can interactively apply the diffs.
这篇关于我怎样才能将一个分支中的特定文件合并到Git中的另一个分支中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!