[英]How can I copy many files, defined by extension, in many folders, from one remote repository branch to another?
It seems, I have changed not only my backend files on the remote branch, but also many frontend files. 看来,我不仅更改了远程分支上的后端文件,而且还更改了许多前端文件。 Now they are changed in my branch and I can't merge it to the master branch.
现在它们在我的分支中已更改,我无法将其合并到master分支。
How can I copy files chosen by extension from one branch into another? 如何将扩展名选择的文件从一个分支复制到另一个分支?
Git does not allow the partial merging of branches. Git不允许分支的部分合并。 That is, when you merge you need to merge all the information - you can't ignore some files and include others... (well, you can, but it's very bad practice and involves just pretending you did a merge).
也就是说,合并时,您需要合并所有信息-您不能忽略某些文件而包括其他文件...(可以,但是,这是非常糟糕的做法,只是假装您进行了合并)。
That said, there are several ways you can proceed. 也就是说,有几种方法可以进行。
You can ignore the fact that your branch is on a remote - in git branches are branches, irrespective of where they are. 您可以忽略分支位于远程的事实-在git分支中,分支是分支,无论它们在哪里。 A
git pull
/ fetch
will download your remote changes so you can work on them. git pull
/ fetch
将下载您的远程更改,以便您可以进行更改。
This involves taking all your changes in your feature branch, adding only those with the extension, and making a large commit with those changes on master
: 这涉及在功能分支中进行所有更改,仅添加具有扩展名的更改,然后对
master
更改进行大量提交:
git checkout feature
git reset master..feature
- reset to the intersection of master
and feature
git reset master..feature
重置为master
和feature
的交集 git add -- *.txt
- add all the .txt
files git add -- *.txt
添加所有.txt
文件 git commit
git reset --hard
to eliminate the files you don't want) git reset --hard
很难清除不需要的文件) git merge
git rebase -i
to interactively break each commit into 2 - those that edit the .txt
files (for example), and those that don't. git rebase -i
以交互方式将每个提交分为2个 -例如编辑.txt
文件的提交和不编辑.txt
文件的提交 。 git cherry-pick
to take only the commits that you want into a new branch, called feature-txt-files-only
for example. git cherry-pick
仅将想要的提交带入新分支,例如, feature-txt-files-only
称为feature-txt-files-only
。 master
branch. master
分支合并。 I will give an example for .py
files. 我将举一个
.py
文件的例子。 Try to do the merge, then 尝试进行合并,然后
find -name '*.py' -print0|xargs -0 git checkout --ours --
or 要么
find -name '*.py' -print0|xargs -0 git checkout --theirs --
"Ours" means the local branch, and "theirs" means the remote branch (except when rebasing, when their meanings are swapped). “我们的”是指本地分支,“他们的”是指远程分支(重新定级时,交换其含义时除外)。
You can do this as many times as necessary for the file types you want to use to clobber the other changes. 对于要用来掩盖其他更改的文件类型,您可以根据需要多次执行此操作。
Then finish the merge in the normal way. 然后以正常方式完成合并。
The only problem is this might not work reliably with files that have been deleted on one of the branches but changed on the other branch. 唯一的问题是,这对于在一个分支上已删除但在另一个分支上已更改的文件可能无法可靠地工作。 So watch out for such cases.
因此,请注意此类情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.