[Practical Git] Clean up commits with git rebase

Source: Internet
Author: User

Sometimes its nice-to-clean up commits before merging them into your main code repo; In this lesson, we go through using git rebase to squash commits together and then rename the Condensed commit message. We also talk about potential issues with rebasing and where to be careful.

// First , you can fetch the remote branch git fetch // Then can see the logs between remote branch and local branchgit log origin/master.

Git rebase-i origin/master

One thing to note is the a rebase is destructive. It actually changes your Git history. You shouldn ' t use a rebase the code that's already been put in your master branch on your remote repository this other Deve Lopers might be using. A rebase have the same function as a Git merge, but it cleans up and destroys history, whereas a merge preserves all histor Y, and includes a merge commit.

The bottom line was that, as long as you have only need to clean up commits that you ' ve made locally or in a pull request branch , you can use the rebase to clean them up before the merge them into your main master branch.

If you had already pushed your commits to a pull request branch, then after you run the rebase, because it ' s destructive, You ' ll need to run:

Git push-f

, for force, to-let Git know this ' re OK with destroying the ' s in a remote branch.

Again, be careful with this, and only use a rebase and a force push if you ' re working on code that hasn ' t been made public yet. One other thing to note are that if at any time during a rebase, you realize you ' ve made a mistake, you can get run the Gi T rebase command with the abort flag to stop the rebase, and return your repo to their state before you started the rebase.

Git rebase--abort

[Practical Git] Clean up commits with git rebase

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.