如何在不解决其他提交冲突的情况下以git为基础,或者在不影响其他提交的情况下压扁我的所有提交? [英] How can I rebase in git without resolving other commit conflicts, or squash all of my commits while leaving others' commits untouched?

查看:61
本文介绍了如何在不解决其他提交冲突的情况下以git为基础,或者在不影响其他提交的情况下压扁我的所有提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 ---A---
/       \
---main--------
  \---B---+A------/
       \-----\--\C-?

以上是我团队回购中的大致情况.功能A是一个巨大的分支,我绝对必须独自离开.我从B分支出来,但一直定期退出,这意味着我拥有A的所有更改,并且与分支C上的main保持最新.这也意味着在我对C的第一次提交和最后一次提交之间,有数十个提交,再加上来自A的大合并.我的回购协议要求将对main的每次推送都压缩,并且我希望避免将其他所有人的工作重新提交给我自己,这是如果我执行 git reset --soft 在我的第一个C提交之前,然后 git rebase -i 迫使我解决每一个冲突,即使不是我自己的提交.

Above is roughly the situation on my team's repo. Feature A is a giant branch that I absolutely have to leave alone. I branched off of B but have been pulling from it periodically, which means that I have all of A's changes and am up to date with main on branch C. This also means that between my first and last commit on C, there are dozens of commits plus a giant merge from A. My repo requires that each push to main be squashed, and I would like to avoid recommitting everyone else's work as my own, which is the result if I do git reset --soft to right before my first C commit, and git rebase -i forces me to resolve every single conflict, even of those that aren't my own commits.

如何重置"密码?并在我开始使用C之前压缩我所有的提交,而不必解决每个其他分支的冲突或将每个提交重新提交为我自己的提交?

How can I "reset" and squash all of my commits to right before I started work on C without having to resolve the conflicts of every other branch or recommit every commit as my own?

更新:我不完全确定该怎么做,但是在C的历史中间使用 git reset --soft 进行提交实际上确实实现了我想要的功能,将我所有的更改都变成了一个更改在前面.我很想知道另一次尝试时出了什么问题.从那里,我签出B并使用 git merge --squash C

Update: I am not entirely sure how, but using git reset --soft to a commit in the middle of C's history actually did exactly what I wanted, pulling all of my changes into one change at the front. I'm curious about what went wrong the other time I tried that. From there, I checked out B and used git merge --squash C

推荐答案

从main创建一个新分支.使用git cherry-pick获取B和C提交.

Create a new branch from main. Use git cherry-pick to get B and C commits.

使用git rebase -i HEAD〜4压缩最后4次提交

use git rebase -i HEAD~4 to squash last 4 commits

这篇关于如何在不解决其他提交冲突的情况下以git为基础,或者在不影响其他提交的情况下压扁我的所有提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆