git branch -m是否对其他开发者有副作用? [英] Does git branch -m have side effects for other developers?

查看:215
本文介绍了git branch -m是否对其他开发者有副作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经学会了如何使用 git branch -m 。如果我这样做,是否会让其他人从我的存储库中取出生活困难?

说我在分支上做了一堆东西 topic1 ,然后做一个

  git分支-m master old_master 
git分支-m topic1 master
git push origin master

然后其他人拉 master 从我的远程仓库中,他们必须做些什么才能使所有的指向正确的地方?我必须告诉所有人重复我的步骤吗?



这是否类似于在推送提交并让其他开发人员悬挂对象之后重新提交提交的问题?

解决方案

我不完全确定您的回购看起来像什么,但这里是最坏的情况。



假设你的 origin repository看起来像这样

 
origin:
o --- o --- A --- B --- C master

并且你的本地仓库看起来像这样,

 
JimPuls:
o --- o --- A --- B --- C主,起源/ master
\
D --- E --- F topic1

然后,在分支重命名后本地存储库看起来像这样:

 
JimPuls:
o --- o --- A --- B --- C old_master,origin / master
\
D --- E --- F master

现在,当您将 master 更改为 origin 时,这将是一个非快速更新。推送后, origin 存储库将如下所示:

 
origin:
o --- o --- A ... B ... C(B&C是孤儿提交)
\
D --- E --- F master

对于可能在 C 之上完成提交的朋友,这可能会很残酷。例如,如果Sally与您合作,她的存储库可能如下所示:

 
Sally:
o --- o- --A --- B --- C来源/主人
\
G --- H ---我主人

现在,如果您执行了非快进操作,并且Sally执行了 fetch ,她的存储库将如下所示:

 
Sally:
D --- E --- F原产地/主人
/
o --- o --- A --- B --- C
\
G --- H --- I master

现在莎莉必须弄清楚如何让她的工作(G,H,I)回到仓库。如果她只是简单地与 origin / master 进行合并,那么B和C中的更改将返回到资源库(oops!)中。相反,她必须 cherry-pick rebase 她的GHI更改为 origin /主

Git让你这么做很酷,但它有点麻烦。你真的希望莎莉注意到这种情况。这就是为什么当你这样做时你应该警告所有其他贡献者,以便他们能够适当地处理这些变化。



注意:上面是最坏的情况。如果您的 topic1 分支在C处偏离 master ,那么更改快进并没有问题。


We've already learned how to switch which branch points to what using git branch -m. If I do this, is it going to make life difficult for the other people pulling from my repository?

Say I do a bunch of stuff on a branch topic1 and then do a

git branch -m master old_master
git branch -m topic1 master
git push origin master

and then somebody else pulls master from the my remote repository, what will they have to do to make everything point to the right place? Will I have to tell everybody to repeat my steps?

Is this akin to the problem of rebasing commits after pushing them and leaving other developers with dangling objects?

解决方案

I'm not exactly sure what your repo looks like but here's the worst-case scenario.

Suppose your origin repository looks like this

origin:
o---o---A---B---C  master

And your local repository looks like this,

JimPuls:
o---o---A---B---C  master, origin/master
         \
          D---E---F topic1

Then, after your branch renames your local repository looks like this:

JimPuls:
o---o---A---B---C  old_master, origin/master
         \
          D---E---F master

Now, when you push master to origin that'll be a non-fast-forward update. After the push, the origin repository will look like this:

origin:
o---o---A...B...C  (B & C are orphaned commits)
         \
          D---E---F master

This can be cruel to your friends who may have done commits on top of C. For example, if Sally was working with you her repository may look like this:

Sally:
o---o---A---B---C  origin/master
                 \
                  G---H---I master

Now, if you do your non-fast-forward push and Sally does a fetch her repository will look like this:

Sally:
          D---E---F  origin/master
         /
o---o---A---B---C  
                 \
                  G---H---I  master

Now Sally has to figure out how to get her work (G, H, I) back into the repository. If she simply does a merge with origin/master then the changes in B and C will be back in the repository (oops!). Instead, she'll have to cherry-pick or rebase her G-H-I changes onto origin/master.

It's cool that Git lets you do that but it's kind of asking for trouble. You're really hoping that Sally notices the situation. This is why you should warn all the other contributors when you do this so they can deal with the change appropriately.

NOTE: the above is a worst-case scenario. If your topic1 branch departed from master at C then that change is a fast-forward and there are no problems.

这篇关于git branch -m是否对其他开发者有副作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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