为什么选择选择更改多个提交?

发布于 2024-12-10 20:44:52 字数 413 浏览 4 评论 0 原文

我这里有 2 个分支,即分支 1 和分支 2。分支1增加了很多新功能,分支2也很稳定。今天,我只想将分支 1 中的 1 个功能合并到分支 2 中。因此,我只需运行 gitcherry-pick 。我想应该只有 中的更改会合并到branch2中。但我发现还有更多其他功能的变化。

我认为它只会获得指定提交的差异,对吧?

仅供参考,branch1 中的提交是从其他开发分支合并的,这是否可能导致此问题?

我做错了什么吗?

谢谢。

I have 2 branches here, say branch1 and branch2. There are lots of new feature added in branch1, and the branch2 is stable. Today, I want to merge just 1 feature from branch1 to branch2. So, I just run git cherry-pick <commit-for-feature1-in-branch1. I suppose there should be only the change in <commit-for-featur1-in-branch1 will be merged into branch2. But I found there are more changes for other features are included.

I thought it will get the diff just for only that specified commit, right?

FYI, the commit in branch1 was merged from other development branch, does this possibly cause this issue?

Anything wrong I did?

Thanks.

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

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

发布评论

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

评论(2

塔塔猫 2024-12-17 20:44:52

我也遇到过这种行为...我已经将其追踪到以下解释,但也许有人进一步澄清了这一点:

  • 您选择一个提交,该提交包含 1 个文件中的 1 个更改
  • 您注意到,不仅提交中包含的更改,而且还包括更多更改(主要包括围绕该更改的更改)

这是因为提交中的更改取决于先前的更改。因此,在创建您想要挑选的目标分支后,这部分代码被更改了多次。

Git 会回溯历史记录,直到首选源与目标匹配并根据此修订创建补丁。这就是为什么可能会出现更多更改......

我发现这种行为有点可怕,因为人们会期望只选择给定提交哈希中的更改

I have also come across this behavior ... I've tracked it down to the following explanation, but perhaps someone clarify this a it more:

  • You cherry pick a commit, the commit contains 1 change in 1 file
  • You notice that not only the change contained in the commit but also more changes (mostly around that change are included)

This is because the change in the commit depends on a previous change. So this area of code was changed multiple time after the target branch you want to cherry pick was created.

Git goes back in the history until the cherry pick source matches the target and creates the patch based on this revision. That's why more changes might appear ...

I find this behavior a bit scary, because one would expect that only the changes from the given commit hash are picked

人事已非 2024-12-17 20:44:52

gitcherry-pick 的作用是获取您指定的提交并读取它与其父级之间的差异。这有效地制作了一个补丁。然后它会将此补丁应用到您当前签出的分支。

就您而言,提交包含其他功能的添加。您可以通过查看此提交使用 git log 生成的补丁来仔细检查提交消息是否与您认为的功能相对应:

git log -p -1 <sha1-of-your-commit>

-p 告诉 log不仅显示提交信息,如作者、日期和提交消息,还包括提交引入的补丁(或差异)。 -1 选项告诉 git log 在 1 次提交后停止列出历史记录。

What git cherry-pick does is it takes the commit that you specify and reads the difference between it and it's parent. This effectively makes a patch. It then applies this patch to your currently checked out branch.

In your case, the commit contained the addition of other features. You can double check that the commit message corresponds to what you thought the feature was by looking at the patch that this commit would generate with git log:

git log -p -1 <sha1-of-your-commit>

The -p tells log to not only show the commit information like author, date and commit message, but to also include the patch (or difference) that the commit introduces. The -1 option tells git log to stop listing history after 1 commit.

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