Git:合并到master,同时自动选择用分支覆盖master文件

发布于 2024-08-02 19:00:06 字数 296 浏览 7 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉风有信 2024-08-09 19:00:06

要忽略 master,当您签出 branch 时:

git merge master --strategy=ours

http://schacon.github.com/git/git-merge.html

作为'计算机语言学家' 莉莉丝河
评论说,这将“忽略‘master’中的所有内容,即使它对新的独立文件进行了更改”。因此,如果您不是 OP 并且想要一个更安全的合并,而不是像 OP 所说的“忘记合并”,那么请使用 Lilith River,并为他的评论点赞,这样他就可以获得荣誉。

git merge -s recursive -X theirs <branch>

To disregard master, when you have branch checked out then:

git merge master --strategy=ours

http://schacon.github.com/git/git-merge.html

As 'Computer Linguist' Lilith River
commented, 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 merge -s recursive -X theirs <branch>
伤痕我心 2024-08-09 19:00:06

在 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.

鼻尖触碰 2024-08-09 19:00:06

我相信您可以使用“我们的”合并策略来做到这一点:

git checkout branch
git merge -s ours master

但这并不完全符合您的要求:它会覆盖当前工作分支分支的内容并且你想要的是将相同的内容放到master上。你真正想要的是一个合并策略他们的,为此我向你指出这个类似的问题 寻找一种方法。实际上,它归结为将 master 重置为指向 branch

I believe you can do this with the 'ours' merge strategy:

git checkout branch
git merge -s ours master

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 onto master. What you really want is a merge strategy theirs, and for that I point you at this similar question for a way to do it. In practice what it boils down to is resetting master to point at branch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文