Git-tips

Any donation is very welcome
Fork me on GitHub

I. Git tips

3. Rewrite a project history

Before going any further, I need to warn you: All changes are definitive! Once again, be very careful when using this.

Fear git rebase!

Yes, once again, this is git rebase which allows to do it. When you're using the interactive option ("-i" for those who didn't read the previous chapter) you can do a lot of things. For example, you can switch the order of a few commits or even delete some! Since there isn't much to tell, I'll provide a quick example:

We start a rebase:

git rebase -i HEAD~2

We now have the following screen:


Git rebase screen

We switch the two commits:


Git rebase switched screen

We save and close. Then we need to push the changes on the repository. Once again, I warn you (like I already did in the previous chapter): we'll use the force-push option so be very careful!

git push -f origin HEAD:the_branch_I_want_to_push_on

That's it!