14

I have just started using git. Rebase is great stuff. I should have used it in a specific earlier case.

is there a perfectly acceptable way to rebase old commits for the sake of clear commits?

griotspeak
  • 13,022
  • 13
  • 43
  • 54

2 Answers2

14

You should positively only do this for commits that have not been pushed upstream. That said, I find it easiest to use git rebase -i <commit> where <commit> is the id of a commit that is at least as old as the newest one you do not want to mess with. When your editor pops up, it will contain instructions about how to squash and/or delete commits.

Swanand
  • 12,317
  • 7
  • 45
  • 62
Brian L
  • 10,757
  • 5
  • 19
  • 17
8

In general, if you've shared a commit with someone else, don't rebase it.

If you haven't shared a commit with anyone else, you can do whatever you want to it.

See the "RECOVERING FROM UPSTREAM REBASE" section of the git-rebase manpage for more info.

Amber
  • 507,862
  • 82
  • 626
  • 550
  • that man page is genuinely disorienting to me. If i have 10 commits and all i want to do is squash 3 4 and 5 together, how would i do that? – griotspeak Feb 10 '11 at 22:09
  • 2
    @griot Start interactive rebase, and mark them to be squashed. – Šimon Tóth Feb 10 '11 at 22:17
  • Note: recovering from a `git push -f` will be easier with Git 2.0: see http://stackoverflow.com/a/20423029/6309 – VonC Dec 06 '13 at 11:50