Git:可以在主分支中创建一个分支,忽略任何合并冲突吗?
除了 master 之外,我还有一个带有一个分支的 git 存储库。我想让那个分支成为主分支——完全覆盖主分支。显然我可以进行合并,但这会导致许多冲突,当我知道我总是想要来自附加分支而不是主分支的文件时,解决它们似乎需要做很多工作。
是否可以将一个分支转换为主分支,或者进行合并并告诉 git 始终优先选择一个分支中的文件而不是另一个分支?
提前致谢!
I've got a git repo with one branch, in addition to the master. I want to make that one branch the master -- overwriting the master completely. Obviously I could do a merge, but this will result in many conflicts, and it seems like a lot of work to resolve them when I know I ALWAYS want the file from the additional branch, not the master.
Is it possible to convert a branch to master, or to do a merge and tell git to always favor the file from one branch over the other?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用重置命令一次性完成此操作:
硬重置将使当前分支指向给定的提交。这将丢弃 master 上尚未在主题分支上的任何提交;它们不会被合并。
对于变基的相同警告也适用于此处:如果您已经将主分支推送到与其他开发人员共享的任何存储库,请不要执行此操作。
You can do this in one shot with the reset command:
A hard reset will make the current branch point to the given commit. This will throw away any commits on the master that are not already on the topic branch; they will not be merged.
The same warning for rebases applies here as well: don't do this if you've already push the master branch to any repository shared with other developers.
如果您是访问此存储库的唯一开发人员,并且它不与其他开发人员共享,则通过创建新分支很容易做到这一点。在开始之前,请确保您的存储库是干净的(所有修改都已签入当前分支)。
备份旧的 master 分支:
删除旧的 master 并创建新的 master:
如果托管在远程服务器上的存储库上,您将需要更新远程:
重要:如果其他开发人员已从您的存储库中拉取,此方法将下次他们从您的存储库中提取或您推送到他们的存储库时,会为他们生成错误。
If you are the only developer accessing this repository and it is not shared with other developers, this is pretty easy to do by creating new branches. Before you begin, make sure that your repository is clean (all modifications have been checked into the current branch).
Make a backup of your old master branch:
Delete old master and create new master:
If hosting on the repository on a remote server, you will need to update the remote:
IMPORTANT: If other developers have been pulling from your repository, this method will generate errors for them the next time they pull from your repo or you push to their repo.
我仍然不是 git 方面的专家,但看起来你想要 rebase 命令:
看起来这会在分支与主分支分离的位置自动将所有更改合并到主分支中,然后在这些更改之上将当前更改重新应用到主分支(因此您不必合并)。
当然,如果您只是想完全覆盖主存储库,我认为如果您使用强制选项,您应该能够将该分支推送到主存储库上。像这样的事情:
然后你的远程将拥有主分支中分支的所有更改,你可以将其拉出来......
I'm still not an expert in git, but it looks like you want the rebase command:
Looks like this will auto-merge all the changes into your master at the point where you're branch diverged from master, then re-apply the current changes to master ontop of those changes (so you won't have to merge).
Of course if you just wanted to completely overwrite the master, I think you should just be able to push that branch onto the master repository if you use the force option. Something like this:
Then your remote will have all the changes from your branch in the master branch, and you can pull it back out...