英文:
git merge, can I substitute some files in one branch with files in another one?
问题
所以,这是情况。我有一个仓库,里面有很多文件。我只修改了大约15个文件...有很多文件我不需要修改,超出了我的工作范围,但出于逻辑原因,它们在同一个仓库中。
我遇到了以下情况:
分支A 分支B
提交A.1
提交A.2 提交B.2
提交A.3 提交B.3
提交B.4
......
提交B.N
分支A是源(主分支),分支B是远程和本地分支,在那里我一直在工作。我需要分支B中最后一次提交B.N的文件状态覆盖分支A(源/主分支),基本上我不想将我的更改合并到A中,我想覆盖那些文件,有没有快速的方法来做到这一点?作为解决方案,我考虑了复制粘贴文件,并在新的提交中覆盖它们,但这样会破坏这些文件的历史记录,有没有使用Git的选项?
英文:
So, this is the situation.
I have a repo with let's say a lot of files. I have only touched let's say about 15 files... there are a lot of files, that I don't need to touch/modify and they are out of my scope of work, but for logic reasons they are in the same repo.
I had the following situation:
Branch A Branch B
Commit A.1
Commit A.2 Commit B.2
Commit A.3 Commit B.3
Commit B.4
.........
Commit B.N
Branch A is the origin (master), Branch B is remote and local, where I kept working, I need the files in branch B, at the state of the last commit B.N to be in branch A (origin / master), so basically I don't want to merge my changes in A, I want to override those files, is there a way to do this quickly?
As a solution I thought in copy and paste the files, and override them in a new commit, but that will mess the history of those files, any options with git?
答案1
得分: 0
以下是翻译好的部分:
你可以进行一个假的合并,在提交之前进行修改。
我建议在一个单独的克隆中执行此操作,以不干扰您当前设置为分支B的现有工作树,您正在该分支上工作。
git switch A
git merge --ours B
# 从B复制文件到A
git commit -m "将B.x 的提交导入A"
git push
git merge --ours B
记录了从B到A的合并,但不会修改A上的任何内容:这为您提供了只复制您想要的文件的机会。
英文:
You can do a fake merge, that you modify before committing.
I would do so in a separate clone, in order to not disturb your existing working tree which is currently set to branch B, where you are working
git switch A
git merge --ours B
# copy files from B to A
git commit -m "Import B.x commit to A"
git push
The git merge --ours B
records a merge from B to A, but does not modify anything on A: that gives you the opportunity to copy only the files you want.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论