关于 git rebase 的一点疑问

2019-12-03 18:08:55 +08:00
 caneman

0.现在有两个分支 master 和 server

1.我在 master 分支执行,git rebase server 和 git rebase server master 结果一致,都仅仅只影响到了 master 分支,server 分支无变化,到这里我觉得没什么问题。

退到 0

这一次我在 master 分支执行 git rebase master server,server 分支按预期的结果发生了变化,但是我疑惑的是: 为什么 master 分支也发生了跟 server 分支一样的变化?(两个分支变得一模一样了)

按理说 master 分支不应该什么也不变吗?

按我的理解 git rebase master server = git checkout server & git rebase master

其实也就是:在 server 分支 ,git rebase master server = git rebase master

那么:在 master 分支 git rebase master server = ?,如果还是 = git rebase master

那么在 master 分支执行完毕后不应该 server 和 master 分支都不发生变化嘛?(相当于 master 分支执行 git rebase master )

2932 次点击
所在节点    git
9 条回复
wangyzj
2019-12-03 19:05:47 +08:00
master <------ master <------ server
|_________________________↑
一种递归的赶脚
zunceng
2019-12-03 19:16:57 +08:00
git rebase [-i | --interactive] [<options>] [--exec <cmd>] [--onto <newbase>]
[<upstream> [<branch>]]
If <branch> is specified, git rebase will perform an automatic git checkout <branch> before doing anything else. Otherwise it remains on the current branch.

If <upstream> is not specified, the upstream configured in branch.<name>.remote and branch.<name>.merge options will be used (see git-config(1) for details) and
the --fork-point option is assumed. If you are currently not on any branch or if the current branch does not have a configured upstream, the rebase will abort.

我读了文档我懂了 你呢
caneman
2019-12-03 19:43:41 +08:00
这是 git help rebase 里面的文档,已经看过了,我上面 git rebase master server = git checkout server & git rebase master 就是从这里看到的,是我理解错了吗?能否不吝赐教?谢谢~
zunceng
2019-12-03 19:58:36 +08:00
rebase 的 upstream 都是远程分支 你操作多了弄混了吧
caneman
2019-12-03 20:10:50 +08:00
@zunceng 他这个写的是 master 和 origin master 是等同的吧?我在 git 手册里面 关于 rebase 的说明里面 看到了 git rebase master server 这种用法,可以在不切换分支的情况下对另一个分支进行 rebase 操作。

我刚刚本地不能复现,可能是 git 版本的问题,我写题目附录里面了。
niming007zh
2019-12-03 20:25:47 +08:00
我跟你讲,git 的 1.6,1.7,1.8.....版本之前都有不少差异,甚至命令都变了。
遇事不决,升级 git。
xingheng
2019-12-03 21:57:21 +08:00
从来都是 git rebase branch1 branch2 这种格式,无视操作前当前分支是什么,记住 branch1 会垫底,branch2 会跑上面去就行了
xingheng
2019-12-03 21:57:21 +08:00
从来都是 git rebase branch1 branch2 这种格式,无视操作前当前分支是什么,记住 branch1 会垫底,branch2 会跑上面去就行了
caneman
2019-12-04 09:06:05 +08:00
@xingheng 对啊,我遇到的情况是,branch1 会把 branch2 上的修改同步一遍,就是两个分支都变成了 branch1 垫底,branch2 跑上面去

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/625609

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX