git merge 是否将提交重新应用到另一个提交上?
我今年 15 岁,刚刚开始使用源代码控制系统来更好地管理我的代码,所以我对这些东西有点陌生。现在我有这个存储库:
[a]---[b]---[d]---[f] master
\
\
[c]---[e] develop
我想在这里结束:
[a]---[b]---[d]---[f]---[g] master
\ /
\ /
[c]---[e]---/ develop
其中 g
相当于执行提交 [c]
和 [e]
<代码>[f]。这是 git checkout master; git mergedevelop,对吧?
I'm 15 and have just started using source control systems to manage my code a little better, so I'm a little new to this stuff. Right now I have this repository:
[a]---[b]---[d]---[f] master
\
\
[c]---[e] develop
I want to wind up here:
[a]---[b]---[d]---[f]---[g] master
\ /
\ /
[c]---[e]---/ develop
where g
is equivalent to performing commits [c]
and [e]
on [f]
. This is git checkout master; git merge develop
, right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您绘制的图片看起来像
git merge
的结果,但您对想要发生的情况的描述听起来像git rebase
。借用 git 社区书籍的“Rebasing”章节(如果您在)
mywork
分支并说你会得到
将合并视为塞在一起两个不同的快照:在本例中,C4 和 C6 组合在一起形成 C7。
Rebase 创建的树看起来就像 C7,但它的历史看起来完全不同。 命令不是合并,而是
假设您给出的
当您发现自己希望时,“我真的希望”我在 C4 而不是 C2 创建了
mywork
分支,'git rebase
是授予它的 djinni。您还可以将变基视为从历史记录中删除一个分支并将其移植到不同的点。不要错过从 C5 和 C6 到 C5' 和 C6' 的微妙变化。尽管这些树看起来是一样的,但它们有不同的父母,从而改变了它们的 git 身份。
The picture you drew looks like the result of
git merge
, but your description of what you want to happen sounds likegit rebase
.Borrowing from the "Rebasing" chapter of the git community-book, if you're on the
mywork
branch and sayyou'll get
Think of a merge as cramming together two different snapshots: in this case C4 and C6 came together to make C7.
Rebase creates a tree that looks just like C7, but its history looks completely different. Say instead of the merge, you gave the command
you'd get
When you find yourself wishing, 'I really wish I'd created the
mywork
branch at C4 instead of C2,'git rebase
is the djinni that will grant it.You could also think of rebase as cutting a branch out of your history and transplanting it on a different point. Don't miss the subtle change from C5 and C6 to C5' and C6'. Although the trees will look the same, they'll have different parents, thus changing their git identities.
你想要 git checkout master; git 合并开发。
这是因为 git merge 采用您想要合并到当前签出分支的分支的名称。因此,您检查所需的目标分支(主分支),然后将另一个分支合并到其中(开发分支)。
如果您查看
git-merge
手册页,您将看到一个与您的几乎相同的图表(尽管垂直翻转)来描述这一点。You want
git checkout master; git merge develop
.This is because
git merge
takes the name of a branch that you want to merge into the currently checked out branch. Thus, you check out your desired destination branch (master) and then merge the other branch into it (develop).If you take a look in the first "Description" section on the
git-merge
man page, you'll see a diagram almost identical to yours (albeit flipped vertically) that describes this.关于合并的另一个很大的帮助是 http://progit.org/book/ch3-2.html< /a> 和 http://gitref.org/branching/#merge。
Another great help about merge is http://progit.org/book/ch3-2.html and http://gitref.org/branching/#merge.
使用 git checkout master 进入 'master' 分支,然后使用 git merge develop 将 'develop' 分支合并到当前 'master' 分支。
It is
git checkout master
to get on 'master' branch, thengit merge develop
to merge 'develop' branch into current 'master' branch.