git只合并现有的文件 [英] git 'merge' only existing files
问题描述
我可以执行仅更新当前分支中现有文件的合并吗?
例如,我有branch1:/ file1,/ x / file2,/ file3 。和branch2:/ file1,/ x / file2,/ z / file4。我想用第一个文件更新第二个分支中的文件file1和file2.作为一个解决方案,我看到在分支1中为这些文件创建单独的提交,并使用chery-选择第二个分支。
UPD:
感谢@fge,我创建了这个解决方案(不像我这么简单):
git co branch2
git co branch1 - ./
git reset ./
git ci -a
git clean -f
branch2
中继续: git checkout branch1 - file1 x / file2
然后 git add
修改后的文件并提交结果。
如果你也想拥有branch1的提交信息,你可以使用 git commit -c branch1
。
请注意, branch1
确实是一个refspec。 git中的一个分支只是一个提交,但作为一个提交具有链接到它的父代,它实际上是一个分支。
Can I perform 'merge' that updates only existing files in current branch?
For example, I have branch1: /file1, /x/file2, /file3. And branch2: /file1, /x/file2, /z/file4. I want to update files file1 and file2 in second branch with files from first.
As a solution I see creating separate commits in branch1 for that files, and than use chery-pick in second branch.
UPD: Thanks to @fge, I've founded that solution (not so simple as I had expected):
git co branch2
git co branch1 -- ./
git reset ./
git ci -a
git clean -f
You can proceed as such while on branch2
:
git checkout branch1 -- file1 x/file2
Then git add
the modified files and commit the result.
If you want to have the commit message of branch1 as well, you could commit with git commit -c branch1
.
Note that branch1
really is a refspec. A branch in git is nothing but a commit, but as a commit has links to its parent(s), it is, in effect, a "branch".
这篇关于git只合并现有的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!