You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(Parts of this one are implicit in the Flight Rules, but I didn't recognize them.)
Here is how I got into trouble.
Open a PR, last commit A. Get feedback requiring lots of fixes.
Add new commits B and C, holding first and second rounds of fixes.
git rebase -i intending to squash C into B, but with literally one extra keystroke squash both C and B into A. Now your local and remote branches each have a single commit, but they are different.
Try to push (thinking that locally you have a second commit, holding C squashed into B) and git correctly says you are trying to destroy remote history.
Solution:
git log -1 origin/YOUR_BRANCH_NAME to recover the hash pr-hash of A you wrote over locally in step 3. above. (Note that the value of pr-hash is in the output of git reflog, but it can be hard to identify especially if you've been thrashing around trying to fix things.)
git reset --hard pr-hash Now you are back to where you were before you started answering PR feedback
git cherry-pick hash-of-B Add the first round of fixes
git cherry-pick hash-of-C Add the second round of fixes
git rebase -i but this time leave B as a pick when you squash C, so you have the original PR plus a single commit holding fixes
git push origin YOUR_BRANCH_NAME
The text was updated successfully, but these errors were encountered:
(Parts of this one are implicit in the Flight Rules, but I didn't recognize them.)
Here is how I got into trouble.
git rebase -i
intending to squash C into B, but with literally one extra keystroke squash both C and B into A. Now your local and remote branches each have a single commit, but they are different.Solution:
git log -1 origin/YOUR_BRANCH_NAME
to recover the hash pr-hash of A you wrote over locally in step 3. above. (Note that the value of pr-hash is in the output ofgit reflog
, but it can be hard to identify especially if you've been thrashing around trying to fix things.)git reset --hard pr-hash
Now you are back to where you were before you started answering PR feedbackgit cherry-pick hash-of-B
Add the first round of fixesgit cherry-pick hash-of-C
Add the second round of fixesgit rebase -i
but this time leave B as a pick when you squash C, so you have the original PR plus a single commit holding fixesgit push origin YOUR_BRANCH_NAME
The text was updated successfully, but these errors were encountered: