樱桃挑选多个提交,而无需浏览每个git应用程序

发布于 2025-01-28 02:58:09 字数 453 浏览 3 评论 0原文

我有分支 a ,有几次提交我需要挑选到分支 b 。 在第一个樱桃挑选中,我添加了我稍后在最后一个提交中删除的代码。

当我尝试使用 first_commit^.. last_commit 樱桃挑选它们时,它仍然会一个挑选提交一一 - 迫使我解决我在第一个提交中添加的代码之间的冲突,即使我真的不需要解决这些冲突 - 因为我在最后的提交中删除了此代码,无论如何我还是试图挑选挑选!

所以我的问题是:是否有一种方法可以挑选一系列提交,而无需一个一个(解决每个人的冲突) - ,但只有最终结果它们在代码上的更改(应用了所有提交后的更改之间的冲突(如果有)和代码的其余部分)。

ps 我无法将a纳入B中,因为它包含了我不想要的其他内容,而且我认为我也尝试重新打击以相似的结果。

谢谢!

I have branch A with a few commits I need to cherry-pick into branch B.
In the first cherry-picks I've added code that I've later removed in the last commits.

When I try to cherry pick them using first_commit^..last_commit it still cherry-picks the commits one by one - forcing me to solve conflicts between the code I added in the first commits and other developers code, even though I don't really need to solve these conflicts- as I've deleted this code in the last commits I'm trying to cherry-pick anyway!

So my question is: is there a way to cherry-pick a range of commits without going through them one by one (solving conflicts for each one of them)- but only the end result of their changes in code (solving conflicts, if any, between the changes after all the commits were applied and the rest of the code).

P.S. I cannot pull A into B as it contains other content I don't want, and I think I've also tried rebasing with similar results..

Thanks!

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

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

发布评论

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

评论(1

幽梦紫曦~ 2025-02-04 02:58:10

一种快速的方法可以是:您可以使用git Merge -squash来创建一个单一的挤压提交,而不是挑选一个单个委托的顺序。


如果您想在最终结果中有一系列提交,那么您需要使用cherry-pickrebase重新命令,您可能必须解决根据提交的基础进行冲突。

您可以尝试避免挑剔问题的提交:

如果您的起始历史记录如下:

*--*--*--*--*--*--*--*--*--* <- main
    \
     \
      x1--a--b--c--d--e--x2 <- feature
      ^                  ^
  problematic commit     |
                     revert of commit x1

您可以尝试运行git cherry-pick x1..e(所有提交最多e <e < /code>,不包括x1),而不是git cherry-pick main..feature(所有人都提交最多功能>功能不包括main main < /code>,但包括x1x2


[更新],从您的评论中,它似乎要编辑您的历史记录(例如:将一些现有的投入分为“零件”您想保留要丢弃的“ vs”零件)。有几种方法:

如果您能够负担得起一个单一提交中的所有开发人员,这是一种方法:

  • 形成分支,创建一个临时分支:
git checkout -b wip
  • 将您的承诺挤在一起,发现&lt; sha&gt ;在您的分支从主分支分配的位置,然后使用git reset -soft
git reset --soft <sha>
git commit -m "my devs in one single commit"
  • 现在重复几个时间:使用以前的提交检查diff,从您的提交
git diff HEAD^ HEAD
# edit a file
git add file
git commit --amend

一旦您的结果仅包含您想要的端口

One quick way can be : instead of cherry-picking a sequence of individual commits you can create one single squashed commit using git merge --squash.


If you want to have a sequence of commits in the end result, then you will need to use cherry-pick or rebase to replay individual commits, and you may have to solve conflicts on a per commit basis.

You can try to avoid cherry-picking the problematic commits :

if your starting history looks like this :

*--*--*--*--*--*--*--*--*--* <- main
    \
     \
      x1--a--b--c--d--e--x2 <- feature
      ^                  ^
  problematic commit     |
                     revert of commit x1

you can try to run git cherry-pick x1..e (all commits up to e, excluding x1) instead of git cherry-pick main..feature (all commits up to feature excluding main, but including x1 and x2)


[update] from your comment, it looks like you want to edit your history (e.g: split some existing commits into "parts you want to keep" vs "parts you want to discard"). There are several ways to do that :

if you can afford to squash all your devs in one single commit, here is one way :

  • form your branch, create a temporary branch :
git checkout -b wip
  • to squash your commits together, spot the <sha> of the commit where your branch forked from master branch, and use git reset --soft :
git reset --soft <sha>
git commit -m "my devs in one single commit"
  • now repeat several time : inspect the diff with previous commit, remove a piece of code from your commit
git diff HEAD^ HEAD
# edit a file
git add file
git commit --amend

Once you have a result which contains only what you want to port, you can rebase or merge with target branch

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