Reputation: 2616
I did an interactive rebase with more commits than I needed to change. I was surprised that the shas of the unnessisary changes were updated. Unfortunately I only realised this happened after I force pushed my updates.
What I did
Starting point
X - Y \
A - B - C *master (C is a merge commit)
\
- D - E *feature-branch
git rebase -i head~3
D
and E
(we'll call this
D1
)D1
commitA
, B
, and C
as pick
and didn't make any changesMy expectation was that everything would look like this:
X - Y \
A - B - C *master
\
- D1 *feature-branch
When I went to my PR, things actually looked like this:
X - Y \
A - B - C *master
\
- A1 - B1 - C1 - D1 *feature-branch
Where A1
, B1
, and C1
had the same commit messages and changes as A
, B
, and C
, but with different shas.
Questions
A1
, B1
, and C1
from my PR without impacting master's A
, B
, and C
?rebase -i
? Why did including A
, B
, and C
in my rebase command make any changes since I just left them as pick
?Upvotes: 1
Views: 386
Reputation: 98509
The easiest way if you just want to delete A1/B1/C1 is to do a git rebase -i C
. Mark A1 as 'reword', and B1 through D1 as 'fixup'. Edit the commit message for A1 to be what you want as the final message.
Now, as to what went wrong: C
is a merge commit.
That means your history graph probably actually looked like this:
A - B - C *master
/ \
...-X-Y-Z - D - E *feature-branch
When you said HEAD~5
, that took the first parent of HEAD five times. Let's say the first parent of C
is Z
instead of B
. That means you're rebasing onto commit X
, and one of the commits you're planting there is A
. The new A
gets a new commit hash because its ancestry (and possibly its content) changed.
You might not have noticed Y
and Z
showing up in the rebase-interactive editor window and just left them as pick
.
Basically, the rebase
takes your nonlinear history and squishes it into being a line. I can't say I recommend using a rebase across a merge commit.
Upvotes: 4
Reputation: 352
If you run git revert
for A1 - B1 - C1 , your new branch will effectively be the one that you desire. And this operation is safer
Upvotes: -1