将git分支合并到master中最好(也是最安全)的方法 [英] Best (and safest) way to merge a git branch into master

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

问题描述

创建了一个来自 master 的新分支,我们称它为 test



有几个开发人员承诺 master 或创建其他分支,然后合并到 master



让我们假设在 test 上工作需要几天时间,并且您希望持续保持 test master 中的提交进行更新。



我会做 git pull origin master 从 test >。



问题1:这是正确的方法吗?其他开发人员可以很容易地处理相同的文件,因为我工作顺便。






我在 test 已完成,我准备将它合并回 master 。以下是我能想到的两种方式:



答:

  git checkout test 
git pull origin master
git push origin test $ b $ git checkout master
git pull origin test

$ b B:

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

我没有使用 - rebase ,因为根据我的理解,rebase会从 master 并将其放在我的头顶上,因此它可以覆盖其他人的更改。



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



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

解决方案

我会如何做到这一点

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

如果我有一个来自远程分支的本地分支,我觉得合并其他分支比这个远程分支更合适。此外,我不会推动我的更改,直到我对我想要推动的内容感到满意为止,并且我也不会推动所有事情,只有我和我的本地存储库。在你的描述中,似乎 test 仅适合你?所以没有理由发布它。



git总是试图尊重你和其他人的变化,所以 - rebase 。我认为我不能适当地解释它,所以看看 Git book - 重新绑定 git-ready:介绍重新绑定稍作描述。这是一个相当酷的功能

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

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

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

I would do git pull origin master from test.

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


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

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.

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

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.

解决方案

How I would do this

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

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 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天全站免登陆