Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I squashed a PR update onto the PR's commit #288

Open
SamPenrose opened this issue Oct 17, 2019 · 2 comments
Open

I squashed a PR update onto the PR's commit #288

SamPenrose opened this issue Oct 17, 2019 · 2 comments

Comments

@SamPenrose
Copy link

SamPenrose commented Oct 17, 2019

(Parts of this one are implicit in the Flight Rules, but I didn't recognize them.)
Here is how I got into trouble.

  1. Open a PR, last commit A. Get feedback requiring lots of fixes.
  2. Add new commits B and C, holding first and second rounds of fixes.
  3. 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.
  4. 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:

  1. 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.)
  2. git reset --hard pr-hash Now you are back to where you were before you started answering PR feedback
  3. git cherry-pick hash-of-B Add the first round of fixes
  4. git cherry-pick hash-of-C Add the second round of fixes
  5. 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
  6. git push origin YOUR_BRANCH_NAME
@RichardLitt
Copy link
Collaborator

Sounds like a good addition, to me! Want to make a PR for this?

@RichardLitt
Copy link
Collaborator

Ping @SamPenrose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants