On a scale of 1-10, my git skills are -5 for anything beyond pull, commit, push.
I was doing a git rebase on my branch to squash my merges together, using git rebase --interactive [my first commit hash]
But as we all know, this will open the editor with all the commits after my first commit.
I wanted to squash my second commit into my first commit, so I smartly decided "Hey, let me use the same command but with the first commit hash I see before my first commit's hash." And so I did.
Diagram for reference
master ------- commitX --- my branch --- commit1 --- commit2 --- ... --- commitINF.
|__________another branch____commitA
I wanted commit2 squash into commit1. To do so, I experimented with running git rebase --interactive commitX
then I squash commit2 into commit1, and ran git push --force-with-lease
Afterwards, I looked at my branch, and commit2
was squashed into commit1
alright. But now my branch also shows commitX
from another branch
in my branch's work history, with all of its changes.
What did I do wrong in this case? How should I go about squashing the first two commits in a branch next time?
More importantly, how do I remove commitX from my branch's history WITHOUT removing it from the repo's work history, so that it still shows up in its branch where it belongs?