Git:合并到master,同时自动选择用分支覆盖master文件
我正在使用 Git 来跟踪我的文档 Latex 源。我想让 master 分支充满适合最终用户发布的文档,这样当有人需要某些东西时,我可以切换到 master 分支,编译并分发文档。
当手册需要重大更新时,我会创建新分支。但是,当手册获得批准后,需要将其合并回主手册中。当从branch合并到master时,我想向Git传递一些命令说:“忘记合并,只需使用branch中的文件em> 覆盖 master 中的文件。”有办法做到这一点吗?具体来说,我想避免每次都打开合并工具。提前致谢。
I am using Git to track my documentation latex source. I want to keep the master branch full of documents that are suitable for end user release, so when someone needs something, i can just switch to the master branch, compile and hand out the document.
I make new branches when a manual needs a major update. But, when the manual is approved, it needs to get merged back into the master. When merging from branch into master, I would like to pass some command to Git to say, "forget the merging, just use the the file from branch to overwrite the file in master." Is there a way to do this? Specifically, I want to avoid opening up a merge tool every time. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要忽略
master
,当您签出branch
时:http://schacon.github.com/git/git-merge.html
作为
'计算机语言学家'莉莉丝河评论说,这将“忽略‘master’中的所有内容,即使它对新的独立文件进行了更改”。因此,如果您不是 OP 并且想要一个更安全的合并,而不是像 OP 所说的“忘记合并”,那么请使用 Lilith River,并为他的评论点赞,这样他就可以获得荣誉。
To disregard
master
, when you havebranch
checked out then:http://schacon.github.com/git/git-merge.html
As
'Computer Linguist'Lilith Rivercommented, this will "ignore everything from 'master', even if it has changes to new, independent files". So if you are not the OP and want a more safe merge that does not as the OP says "forget the merging", then use this excellent safe command from Lilith River, and upvote his comment up so he gets credit.
在 Git 1.7.1 版本中,您可以使用“-Xtheirs”来合并分支本身。
例如,如果您从 master 分支开始,
从 master 开始
git checkout -b editBranch
-- 编辑你的文件 --
git add 。
git commit -m“更新了文件”
git checkout大师
git merge -Xtheirs editBranch git merge -Xtheirs editBranch
我看到的另一种方法是基于 这篇文章 是对 editBranch 进行硬重置。例如:
git checkout -b editBranch
-- 编辑你的文件 --
git add 。
git commit -m“更新了文件”
git checkout大师
git reset --hard edit分支
我认为第二种方式可能是更好的玩法,但我还没有机会充分尝试它。
In version 1.7.1 of Git, you can use "-Xtheirs" to merge in the branch itself.
For example, if you start in your master branch,
starting in master
git checkout -b editBranch
-- edit your files --
git add .
git commit -m "Updated the files"
git checkout master
git merge -Xtheirs editBranch
Another way that I've seen to do this based off this post is to do a hard reset off the editBranch. For example:
git checkout -b editBranch
-- edit your files --
git add .
git commit -m "Updated the files"
git checkout master
git reset --hard editBranch
I think this second way might be the better play, but I haven't had a chance to play around with it enough yet.
我相信您可以使用“我们的”合并策略来做到这一点:
但这并不完全符合您的要求:它会覆盖当前工作分支
分支
的内容并且你想要的是将相同的内容放到master
上。你真正想要的是一个合并策略他们的
,为此我向你指出这个类似的问题 寻找一种方法。实际上,它归结为将master
重置为指向branch
。I believe you can do this with the 'ours' merge strategy:
But this doesn't do exactly what you want: it override the contents of the current working branch
branch
and what you want is to get the same contents ontomaster
. What you really want is a merge strategytheirs
, and for that I point you at this similar question for a way to do it. In practice what it boils down to is resettingmaster
to point atbranch
.