S. McGraw S. McGraw - 1 year ago 100
Git Question

How to keep only head changes in a git rebase

I'm currently in the middle of a lengthy rebase going through a dozen or so commits. I've structured things in my dev process such that only the changes from

is what I want to keep - all other conflicts (e.g. commit hash
) should be deleted.

Is there a way to simply remove all changes related to the
>>>>>>> b06a1dd
and keep the changes that Git will label
<<<<<<< HEAD
in one fell swoop, so I don't have to keep typing
git rebase --continue
, deal with more conflicts from more commit hashes, and only keep the

Answer Source

If you are willing to start the rebase over (git rebase --abort), then this should do what you need:

git rebase -X ours upstream

where upstream is the branch you are rebasing onto.

As noted in this answer, in the Git rebase docs, and elsewhere, the ours vs. theirs labels are slightly more confusing for rebasing than for merging. After starting a rebase, Git creates an anonymous branch and starts applying commits to it. Since ours means "keep changes from the current branch", that current branch will be HEAD, which contains upstream and any changes already applied by rebase.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download