How can I rebase in git without resolving other commit conflicts, or squash all of my commits while leaving others' commits untouched?

跟風遠走 提交于 2021-02-20 03:51:44

问题


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

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.

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?

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


回答1:


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

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



来源:https://stackoverflow.com/questions/65185929/how-can-i-rebase-in-git-without-resolving-other-commit-conflicts-or-squash-all

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!