git merge 是否将提交重新应用到另一个提交上?

发布于 2024-09-05 00:56:30 字数 474 浏览 7 评论 0原文

我今年 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

谎言 2024-09-12 00:56:30

您绘制的图片看起来像 git merge 的结果,但您对想要发生的情况的描述听起来像 git rebase

借用 git 社区书籍的“Rebasing”章节(如果您在) mywork 分支并说

$ git merge origin

你会得到

git merge History

将合并视为塞在一起两个不同的快照:在本例中,C4 和 C6 组合在一起形成 C7。

Rebase 创建的树看起来就像 C7,但它的历史看起来完全不同。 命令不是合并,而是

$ git rebase origin

假设您给出的

alt text

当您发现自己希望时,“我真的希望”我在 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 like git rebase.

Borrowing from the "Rebasing" chapter of the git community-book, if you're on the mywork branch and say

$ git merge origin

you'll get

git merge history

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

$ git rebase origin

you'd get

alt text

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.

別甾虛僞 2024-09-12 00:56:30

你想要 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.

鸠书 2024-09-12 00:56:30

使用 git checkout master 进入 'master' 分支,然后使用 git merge develop 将 'develop' 分支合并到当前 'master' 分支。

It is git checkout master to get on 'master' branch, then git merge develop to merge 'develop' branch into current 'master' branch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文