简体   繁体   中英

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

 ---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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM