Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有选择地将文件的*部分*与git合并?_Git_Git Merge - Fatal编程技术网

有选择地将文件的*部分*与git合并?

有选择地将文件的*部分*与git合并?,git,git-merge,Git,Git Merge,我希望有选择地将文件的某些部分与git合并 我有两个分支——称它们为master和changed——它们是一个commit;若我将主控合并到已更改的中,它将快速前进 但是,我只想在一个文件中合并一些部分,从changed到master 有没有一个干净的方法来做到这一点——例如,git在每次更改前都会询问?还是我被困在手上?(虽然不是世界末日,但我还是不想,而且——是的——如果我有更多的计划,这本可以避免的——这就是生活。)试试这个: git merge --no-ff --no-commit c

我希望有选择地将文件的某些部分与git合并

我有两个分支——称它们为master和changed——它们是一个commit;若我将主控合并到已更改的中,它将快速前进

但是,我只想在一个文件中合并一些部分,从changed到master

有没有一个干净的方法来做到这一点——例如,git在每次更改前都会询问?还是我被困在手上?(虽然不是世界末日,但我还是不想,而且——是的——如果我有更多的计划,这本可以避免的——这就是生活。)

试试这个:

git merge --no-ff --no-commit changed    # Merge in 'changed' but don't commit
git reset <path/to/your/file>            # Reset the stage state but not 
                                         # the working version of the file
git add -p <path/to/your/file>           # Start adding in interactive mode

(Git will prompt you for each hunk; you can split hunks up if necessary.)

git commit                               # Finally commit the merge with only
                                         # the bits you chose to stage
git merge--no ff--no commit changed#在'changed'中合并,但不提交
git重置#重置阶段状态,但不重置
#文件的工作版本
git add-p#以交互模式开始添加
(Git会提示您输入每一个大块头;如果需要,您可以拆分大块头。)
git commit#最终仅使用
#你选择的舞台片段
但是,请注意,这样做会使Git认为文件已完全合并,因此,如果有人再次合并到同一分支中,则该提交的其他更改仍不会合并到该分支中。这可能不是你想要的


如果您需要有关
git add
交互模式中各种选项含义的帮助,请参阅“交互模式”部分中
git help add
的输出。

如广告所示,尽管我将交互模式的“add-p”更改为“add-I”。我希望git merge能够直接支持与大块头交互工作。是的,很遗憾你不能在这里使用mergetool。另外,有没有办法一次处理多个文件,或者我只需要编写一个循环就可以了?