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_Bitbucket - Fatal编程技术网

Git 从分支将特定文件合并/复制到主文件

Git 从分支将特定文件合并/复制到主文件,git,bitbucket,Git,Bitbucket,我运行以下命令查找在分支中更改但在主目录中未更改的文件名: git diff --name-status master..branchName 它给出了一个包含完整路径的文件名列表 现在我已经在本地机器上克隆了master,并想复制master中更改的文件。我说了copy,因为我不想合并并陷入冲突 有没有办法获得在相关文件夹中有文件的修补程序?您可以将git diff命令的输出重定向到一个文件,而不是手动复制它们 $ git diff master..branchName -- the/rel

我运行以下命令查找在分支中更改但在主目录中未更改的文件名:

git diff --name-status master..branchName
它给出了一个包含完整路径的文件名列表

现在我已经在本地机器上克隆了
master
,并想复制master中更改的文件。我说了
copy
,因为我不想合并并陷入冲突


有没有办法获得在相关文件夹中有文件的修补程序?您可以将git diff命令的输出重定向到一个文件,而不是手动复制它们

$ git diff master..branchName -- the/relevant/path1 the/relevant/path2 ... > my.patch
然后使用
git apply my.patch
一次应用所有更改

另一个选项是签出所需的文件/目录:

$ git checkout master
$ git chechout branchName -- the/relevant/path1 the/relevant/path2 ...

您想要的是使分支和存储库的工作目录和索引指向主提交

方法是:

为了完全覆盖主分支中的文件,是否需要分支中某些文件的修补程序或逐字复制?
git checkout yourBranch
git branch tempBranch   // It is allways safer create a temporal branch when you play with git-reset
git reset --soft master // This moves to master commit but does not touch your working directory and index area.