git只合并另一个分支上特定的文件

如果只想将feature分支的某个文件f.txt合并到master分支上。

1: git checkout feature

2: git checkout --patch master f.txt

第一个命令: 切换到feature分支;

第二个命令:合并master分支上f文件到feature分支上,将master分支上 f 文件追加补丁到feature分支上 f文件。你可以接受或者拒绝补丁内容。

如果只是简单的将feature分支的文件f.txt copy到master分支上;

git checkout master

git checkout feature f.txt

Apply this hunk to index and worktree [y,n,q,a,d,/,K,j,J,g,e,?]?

y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk nor any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk nor any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help

翻译

y - 存储这个hunk
n - 不存储这个hunk
q - 离开,不存储这个hunk和其他hunk
a - 存储这个hunk和这个文件后面的hunk
d - 不存储这个hunk和这个文件后面的hunk
g - 选择一个hunk
/ - 通过正则查找hunk
j - 不确定是否存储这个hunk,看下一个不确定的hunk
J - 不确定是否存储这个hunk,看下一个hunk
k - 不确定是否存储这个hunk,看上一个不确定的hunk
K -不确定是否存储这个hunk,看上一个hunk
s - 把当前的hunk分成更小的hunks
e - 手动编辑当前的hunk
? - 输出帮助信息