[英]How to merge specific file from one branch to another branch
I have two files in branchB called ComfirmPhone.java and DesignSignIn.java.我在分支 B 中有两个文件,名为 ComfirmPhone.java 和 DesignSignIn.java。 I only want to merge these two code in the branchA.
我只想在分支A中合并这两个代码。 Here is my problem.
这是我的问题。 ComfirmPhone.java is a brand new file that branchA does not exist whereas DesignSignIn.java exists in branchA already.
ComfirmPhone.java 是一个全新的文件,branchA 不存在,而 DesignSignIn.java 已经存在于 branchA 中。 There is little bit more code added in DesingSignIn.java branchB looking to combine the code in branchA.
在 DesingSignIn.java 分支 B 中添加了更多代码,希望合并分支 A 中的代码。
Here is the command I've tried (I am in branchA now):这是我尝试过的命令(我现在在 branchA 中):
git checkout --patch branchB ConfirmPhone.java
However, the command does not detect ConfirmPhone.java.但是,该命令未检测到 ConfirmPhone.java。 and also I've tried:
我也试过:
git merge --no-ff --no-commit branchB
It does merge, but it does not specify two files (ComfirmPhone.java and DesignSignIn.java) I am looking for.它确实合并,但没有指定我正在寻找的两个文件(ComfirmPhone.java 和 DesignSignIn.java)。
The branchB has been commited already and both branch are up-to-date (git pull). branchB 已经提交,并且两个分支都是最新的(git pull)。 If anyone can show me the command how to merge the ONLY two files to branchA, it would be helpful
如果有人可以向我展示如何将仅有的两个文件合并到分支 A 的命令,那将很有帮助
Every commit is a collection of all your files.每个提交都是您所有文件的集合。 Any file in any commit can be copied out into the worktree.
任何提交中的任何文件都可以复制到工作树中。 A branch name is merely the name of a commit.
分支名称只是提交的名称。
The case where the file doesn't exist is thus straightforward.文件不存在的情况因此很简单。 Let's say you are in
branchA
where there is no file B.txt , and you happen to know that branchB
contains a file B.txt and you wish that version of that file were present in branchA
.假设您在没有文件B.txt的
branchA
中,并且您碰巧知道branchB
包含文件B.txt并且您希望该文件的版本存在于branchA
中。 Then say然后说
git checkout branchB -- B.txt
Presto, the file appears in the worktree. Presto,文件出现在工作树中。 Of course, it is now a "new" file like any other "new" file;
当然,它现在是一个“新”文件,就像任何其他“新”文件一样; it is not "part" of
branchA
until you add
it and commit
(while in branchA
).在您
add
并commit
(在branchA
中)之前,它不是branchA
的“一部分”。
The case where the file does exist in both branches is similar but now if you don't want to overwrite the worktree version completely you want a --merge
checkout.文件确实存在于两个分支中的情况类似,但现在如果您不想完全覆盖工作树版本,则需要
--merge
签出。 So let's say you are in branchA
where there is a file A.txt ;因此,假设您在
branchA
中,其中有一个文件A.txt ; that means the worktree also contains that version of the file A.txt .这意味着工作树还包含该版本的文件A.txt 。 And let's say you happen to know that
branchB
also contains a file A.txt and you want to merge that version of the file into this version of the file.假设您碰巧知道
branchB
还包含一个文件A.txt并且您想将该文件版本合并到该文件版本中。 Then say然后说
git checkout --merge branchB -- A.txt
The result is that the two versions of A.txt are merged in the worktree, if they can be automatically merged.结果是A.txt的两个版本在工作树中合并,如果它们可以自动合并的话。 If they cannot be automatically merged, you are left with a version of A.txt marked up with the merge conflict;
如果它们不能自动合并,则留下一个带有合并冲突标记的A.txt版本; edit it to resolve the conflict.
编辑它以解决冲突。 Either way, now
add
the file, and commit
.无论哪种方式,现在
add
文件,并commit
.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.