将Git分支合并到master中的最佳(最安全)方法是什么? [英] What is the best (and safest) way to merge a Git branch into master?

查看:232
本文介绍了将Git分支合并到master中的最佳(最安全)方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

master 创建了一个新分支,我们称之为 test

A new branch from master is created, we call it test.

有几个开发人员要么提交给 master ,要么创建其他分支,然后合并为 master

There are several developers who either commit to master or create other branches and later merge into master.

让我们说 test 的工作需要几天的时间,而您想继续保持测试更新为 master 内部的提交。

Let's say work on test is taking several days and you want to continuously keep test updated with commits inside master.

我会做来自 test 的git pull origin master

I would do git pull origin master from test.

问题1:这是正确的方法吗?其他开发人员可以轻松地像处理btw一样处理相同的文件。

Question 1: Is this the right approach? Other developers could have easily worked on same files as I have worked btw.

我在上的工作测试完成,我准备将其合并回 master 。这是我可以想到的两种方法:

My work on test is done and I am ready to merge it back to master. Here are the two ways I can think of:

A:

git checkout test
git pull origin master
git push origin test
git checkout master
git pull origin test 

B:

git checkout test
git pull origin master
git checkout master
git merge test

我没有使用-rebase ,因为据我了解,rebase将从 master 并在其上堆叠我的内容,因此它可能会覆盖其他人所做的更改。

I am not using --rebase because from my understanding, rebase will get the changes from master and stack mine on top of that hence it could overwrite changes other people made.

问题2:这两种方法中的哪一种是正确的?有什么区别?

Question 2: Which one of these two methods is right? What is the difference there?

所有这些目标都是使我的 test 分支保持最新状态。发生在 master 中,后来我可以将它们合并回 master ,希望使时间轴尽可能保持线性。

The goal in all of this is to keep my test branch updated with the things happening in master and later I could merge them back into master hoping to keep the timeline as linear as possible.

推荐答案

我该怎么做

git checkout master
git pull origin master
git merge test
git push origin master

如果我有一个来自远程分支的本地分支,那么除了将这个分支与远程分支合并之外,我不满意。另外,我不会推送更改,直到对要推送的内容感到满意并且也不会推送所有仅适用于我和我的本地存储库的东西。在您的描述中,看来 test 只适合您吗?因此,没有理由发布它。

If I have a local branch from a remote one, I don't feel comfortable with merging other branches than this one with the remote. Also I would not push my changes, until I'm happy with what I want to push and also I wouldn't push things at all, that are only for me and my local repository. In your description it seems, that test is only for you? So no reason to publish it.

git总是尝试尊重您的更改和其他更改,因此-会重新设置。我认为我无法适当地解释它,因此请参阅 Git书-重新定基已准备好git:重新定基进行一些说明。这是一个很酷的功能

git always tries to respect yours and others changes, and so will --rebase. I don't think I can explain it appropriately, so have a look at the Git book - Rebasing or git-ready: Intro into rebasing for a little description. It's a quite cool feature

这篇关于将Git分支合并到master中的最佳(最安全)方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆