变基后是否需要执行提交?

发布于 2024-08-29 15:39:32 字数 182 浏览 6 评论 0原文

我刚刚将一个功能分支重新设置为另一个功能分支(准备将所有内容重新设置为我的主人的头),并且它涉及相当多棘手的合并解决方案。

变基是否会自动保存为某处的提交?

这些修改到底在哪里?我在 gitk 或 git log --oneline 中看不到任何内容。

(当我在变基后合并回我的分支时,同样的问题。)

I've just rebased a feature branch onto another feature branch (in preparation for rebasing everything to the head of my master), and it involved quite a few tricky merge resolutions.

Is the rebase automatically saved as a commit somewhere?

Just where do those modifications live? I can't see anything in gitk, or git log --oneline.

(Same question for when I merge back my branch after rebasing.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

梦境 2024-09-05 15:39:32

Rebase 正在将提交移动到另一个分支之上。如果移动的提交导致合并冲突,则会更改此提交以反映合并解决方案。

变基的目的是让您的提交看起来就像是对您变基的分支的更改。因此,最合乎逻辑的方法是将合并冲突合并到这些提交中。因此不需要额外的提交。

合并是不同的,因为它是将分歧的分支合并在一起的显式操作。每个分支中的提交都不会更改。冲突解决反映在合并提交中。

Rebase is moving commits on top of another branch. If a commit that is moved causes merge conflict, this commit is changed to reflect merge resolution.

The purpose of rebase is make your commits look as if they were changes to the branch you rebase onto. So the most logical way is to incorporate merge conflicts into these commits. No additional commits is required thus.

Merge is different, because it's an explicit action of merging diverged branches together. No commits in each of branches is changed. Conflict resolution is reflected in the merge commit.

无畏 2024-09-05 15:39:32

是的,成功的变基和合并会产生提交。他们只是不会提交需要解决的冲突,但是变基(或合并)的输出会告诉您这种情况已经发生以及如何解决。

对于变基,您只需要解决索引中的冲突,然后git rebase --continue

对于合并,您需要进行提交 (git commit),但系统会记住这是一次合并,并且会提供合适的默认提交消息供您编辑。

Yes, successful rebases and merges make commits. They only won't make a commit of there are conflicts that need resolving, but then the output of the rebase (or merge) will tell you that this has happened and how to resolve it.

For a rebase, you just need to resolve the conflicts in the index and then git rebase --continue.

For a merge, you need to make the commit (git commit), but the fact that it's a merge will be remembered and a suitable default commit message will be supplied for you to edit.

囚你心 2024-09-05 15:39:32

过去(2006 年,1.5.3 之前和 它的用户手册),git rebase

择优挑选的一个特殊情况是如果您想移动整个分支
到较新的“基础”提交。
这是由 git-rebase 完成的。
您指定要移动的分支(默认 HEAD)以及将其移动到的位置(无默认值),
和:

  • gitcherry-picks 该分支中的每个补丁,
  • 将其应用到目标之上,
  • 并将 refs/heads/ 指针移至新创建的提交。

因此根据定义,将进行提交(并且无需进行提交)

变基的一个特殊情况是当您想要划分工作、移动(并重新创建新的)提交时。
来自同一个教程(作为变基后不需要任何进一步提交的说明):

假设您在当前 HEAD 中混合了两个功能的开发,一个名为“dev”的分支。

x-x-x-x  (master)
       \ 
        -f1a-f1b-f1c-f2a-f2b-f2c (dev, HEAD)

您想将它们分为“dev1”和“dev2”。假设 HEAD 是一个分支 master,那么您可以查看

git log master..HEAD

或者只是获取提交的原始列表

git rev-list master..HEAD

无论哪种方式,假设您在 dev1 中找出所需的提交列表并创建该分支:

git checkout -b dev1 master
for i in `cat commit_list`; do
    git-cherry-pick $i
done

        -f1a'-f1b'-f1c' (dev1, HEAD)
       /
x-x-x-x  (master)
       \ 
        -f1a-f1b-f1c-f2a-f2b-f2c (dev)

您可以使用您编辑的列表的另一半来生成 dev2 分支,但如果您不确定是否忘记了某些内容,或者只是不想进行手动工作,那么你可以使用 git-rebase 来为你做这件事。

git checkout -b dev2 dev    # Create dev2 branch
git-rebase --onto master dev1   # Subreact dev1 and rebase

这将找到 dev 中且不在 dev1 中的所有补丁,将它们应用到 master 之上,并调用结果 dev2 .

        -f1a'-f1b'-f1c' (dev1, HEAD)
       /
x-x-x-x  (master)
       \ 
        -f2a-f2b-f2c (dev2, HEAD)

In the old days (2006, before 1.5.3 and its user manual), git rebase was presented like so:

A special case of cherry-picking is if you want to move a whole branch
to a newer "base" commit.
This is done by git-rebase.
You specify the branch to move (default HEAD) and where to move it to (no default),
and:

  • git cherry-picks every patch out of that branch,
  • applies it on top of the target,
  • and moves the refs/heads/<branch> pointer to the newly created commits.

So by definition, commits will be made (and no commit need to be done)

A special case of rebase is when you want to divide your work, moving (and recreating new) commits.
From the same tutorial (as an illustration of not needing any further commit after a rebase):

Suppose you've mixed up development of two features in the current HEAD, a branch called "dev".

x-x-x-x  (master)
       \ 
        -f1a-f1b-f1c-f2a-f2b-f2c (dev, HEAD)

You want to divide them up into "dev1" and "dev2". Assuming that HEAD is a branch off master, then you can either look through

git log master..HEAD

or just get a raw list of the commits with

git rev-list master..HEAD

Either way, suppose you figure out a list of commits that you want in dev1 and create that branch:

git checkout -b dev1 master
for i in `cat commit_list`; do
    git-cherry-pick $i
done

        -f1a'-f1b'-f1c' (dev1, HEAD)
       /
x-x-x-x  (master)
       \ 
        -f1a-f1b-f1c-f2a-f2b-f2c (dev)

You can use the other half of the list you edited to generate the dev2 branch, but if you're not sure if you forgot something, or just don't feel like doing that manual work, then you can use git-rebase to do it for you.

git checkout -b dev2 dev    # Create dev2 branch
git-rebase --onto master dev1   # Subreact dev1 and rebase

This will find all patches that are in dev and not in dev1, apply them on top of master, and call the result dev2.

        -f1a'-f1b'-f1c' (dev1, HEAD)
       /
x-x-x-x  (master)
       \ 
        -f2a-f2b-f2c (dev2, HEAD)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文