git Branch -m 对其他开发人员有副作用吗?
我们已经已经学会了如何使用git切换哪个分支指向什么
分支-m
。 如果我这样做,是否会让其他从我的存储库中提取数据的人的生活变得困难?
假设我在分支 topic1
上做了很多事情,然后做了 a
git branch -m master old_master
git branch -m topic1 master
git push origin master
,然后其他人从我的远程存储库中提取了 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不太确定你的仓库是什么样子,但这是最坏的情况。
假设您的
origin
存储库如下所示并且您的本地存储库如下所示,
然后,在您的分支重命名后,您的本地存储库如下所示:
现在,当您将
master
推送到 < code>origin 这将是一个非快进更新。 推送后,origin
存储库将如下所示:这对于可能在
C
上完成提交的朋友来说可能很残酷。 例如,如果 Sally 正在与您一起工作,她的存储库可能如下所示:现在,如果您执行非快进推送并且 Sally 执行
fetch
,她的存储库将如下所示:现在 Sally 有找出如何将她的工作(G、H、I)放回到存储库中。 如果她只是与
origin/master
进行合并,那么 B 和 C 中的更改将返回到存储库中(哎呀!)。 相反,她必须cherry-pick
或rebase
她的GHI更改到origin/master
。Git 允许你这样做很酷,但这有点自找麻烦。 你真的希望莎莉注意到这种情况。 这就是为什么您在执行此操作时应该警告所有其他贡献者,以便他们能够适当地处理更改。
注意:以上是最坏的情况。 如果您的
topic1
分支在 C 处从master
出发,那么该更改是快进,不会有任何问题。I'm not exactly sure what your repo looks like but here's the worst-case scenario.
Suppose your
origin
repository looks like thisAnd your local repository looks like this,
Then, after your branch renames your local repository looks like this:
Now, when you push
master
toorigin
that'll be a non-fast-forward update. After the push, theorigin
repository will look like this: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:Now, if you do your non-fast-forward push and Sally does a
fetch
her repository will look like this: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 tocherry-pick
orrebase
her G-H-I changes ontoorigin/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 frommaster
at C then that change is a fast-forward and there are no problems.基本上,您的操作与以下内容相同:
并且它们将具有完全相同的效果:其他人都将获得
topic1
分支(不过,它被命名为master
)及其祖先直到master
和topic1
第一次出现分歧。 旧的master
分支就躺在他们的存储库中,并将在将来的某个时候被垃圾收集,因为没有任何东西指向它了。如果
topic1
是源自master
当前HEAD
的分支,那么您在这里就可以了。 否则,您将陷入“重写历史”的情况,这可能会弄乱您的标签。 您需要仔细考虑您真正想要实现的目标。 也许一个简单的 git merge 会更好地为您服务?Basically your operations are the same as:
And they will have exactly that effect: Everybody else will get the
topic1
branch (it’s namedmaster
for them, though) and its ancestry up to the point wheremaster
andtopic1
first diverged. The oldmaster
branch is then lying around in their repositories and will be garbage collected at some point in the future because nothing points to it anymore.If
topic1
is a branch that originated from the currentHEAD
ofmaster
you will be fine here. Otherwise you will get into the “rewriting history” situation which can make a mess of your e.g. your tags. You need to think carefully about what you’re really trying to achieve. Maybe a simplegit merge
will serve you better?