Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can i rebase old commits?

Tags:

git

rebase

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?

like image 836
griotspeak Avatar asked Feb 10 '11 22:02

griotspeak


People also ask

Can you squash old commits?

Keep in mind that you need at least one commit to be picked before the one you want to squash in order to be able to do so, which means you can't choose to squash the first one. Every commit you squash will be squashed into the previous one that was executed.

Does rebase delete commits?

Running rebase in interactive mode and executing subcommands like squash or drop will remove commits from your branche's immediate log.

Can I reorder commits with rebase?

Interactive Rebase also allows you to reorder commits. Simply drag and drop a commit between two existing commits to reorder history.

Do I need to commit before git rebase -- continue?

For each change you make, you'll need to perform a new commit, and you can do that by entering the git commit --amend command. When you're finished making all your changes, you can run git rebase --continue . As before, Git is showing the commit message for you to edit.


2 Answers

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.

like image 79
Brian L Avatar answered Oct 04 '22 13:10

Brian L


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.

like image 44
Amber Avatar answered Oct 04 '22 11:10

Amber