4

I've been asked to "rebase and squash (my) commits into a single commit?" for a pull request https://github.com/samtools/htsjdk/pull/34#issuecomment-45226559

It's the first time I'm doing this and I think I only do wrong things. I'm currently lost.

Last time I tried something:

$ git branch
* fastq
$ git status
$ git merge-base fastq master 
67901f963470a1cd2f8477f736b6b2192343485c
$ git rebase --interactive 67901f963470a1cd2f8477f736b6b2192343485c

(... tried things, ... pulled, pushed, etc...)

$ git rebase --continue
error: Ref refs/heads/fastq is at a3aa885e4943279a7ece9e2eae85b1a80c41af32 but expected c5dc7c69108d1d72cf9eeb0144332075b06fea71
fatal: Cannot lock the ref 'refs/heads/fastq'.

what should be done to answer the reviewer's need ?

update: when i try to push

$ git push origin fastq
To https://github.com/lindenb/htsjdk.git
 ! [rejected]        fastq -> fastq (non-fast-forward)
error: failed to push some refs to 'https://github.com/lindenb/htsjdk.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.
Pierre
  • 34,472
  • 31
  • 113
  • 192
  • Duplicate of [How can I squash my last X commits together using git?](http://stackoverflow.com/questions/5189560/how-can-i-squash-my-last-x-commits-together-using-git) –  Jun 06 '14 at 08:04
  • Duplicate of [Git - combining multiple commits before pushing](http://stackoverflow.com/q/6934752/456814). –  Jun 06 '14 at 08:05
  • Duplicate of [how to squash all my commits into one - github](http://stackoverflow.com/q/14534397/456814). –  Jun 06 '14 at 08:10
  • 1
    @Cupcake: those duplicate don't help: it just explains how to run a rebase (that's what I've done) , not how to fix it. – Pierre Jun 06 '14 at 09:38
  • possible duplicate of [Force git to overwrite remote files on push](http://stackoverflow.com/questions/10510462/force-git-to-overwrite-remote-files-on-push) – random Jun 08 '14 at 23:03

1 Answers1

4

Regarding the rebase in your fasq branch, that would be:

git checkout fastq
git rebase -i 67901f963470a1cd2f8477f736b6b2192343485c (last commmit before your change)

# select s for each commmit in order to squash them)

You will have to force push your branch once your commit is rebase/squashed, since the history is different.

git checkout fastq
git push -f

That will update the PR (Pull Request) automatically.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • `$ git rebase -i 67901f963470a1cd2f8477f736b6b2192343485c` returns "It seems that there is already a rebase-merge directory". I then tried: `git rebase --continue` -> ` error: Ref refs/heads/fastq is at a3aa885e4943279a7ece9e2eae85b1a80c41af32 but expected c5dc7c69108d1d72cf9eeb0144332075b06fea71 fatal: Cannot lock the ref 'refs/heads/fastq'.` – Pierre Jun 06 '14 at 08:02
  • @Pierre simply abort the current rebase, or clone your fork again and try it in that new local cloned repo. – VonC Jun 06 '14 at 08:29
  • 1
    I `git rebase --abort` and `git rebase -i 67901f963470a1cd2f8477f736b6b2192343485c` , replaced all the `pick` by `squash` starting from 2nd line. -> `could not apply f6f8cba... improve fastq` and the file src/java/htsjdk/samtools/fastq/FastqRecord.java has been modified (diff statements inserted HEAD/f6f8cba...) – Pierre Jun 06 '14 at 09:35
  • @Pierre yes, that is why I would experiment in a brand new clone of your fork. – VonC Jun 06 '14 at 09:38