If many people develop a large project (e.g. Chromium), many changes can be created all the time. If we update the code, we need to rebuild all the changed files which may take a lot of time.
Let us assume the name of the major develop branch is master
. To speed up our build, we can checkout and update master
branch everyday and then start a build before we get off work (or before the meal time). The build will be finished when we get back to work next morning. We can call it daily build
.
Our goal is to avoid too many file changes in our local workspace between two daily build. So rebuild our local changes will be fast because it is incremental build.
If we need to checkout among different feature branches, and some of the branch may be created several days ago, and it has many diff from the current master
branch, what should we do? The answer is to use git rebase
in the right way.
For example, we are currently on latest master
branch, and we have a feature branch named my-feature
which is checked out from earlier version of master
branch.
1 | A---B---C---F---...---G (HEAD master) |
If we need to rebase my-feature
on to latest master
branch, we have different ways:
- One way is: 1)
git checkout my-feature
, 2)git rebase master
. But when we checkout tomy-feature
branch in step 1, many files in our workspace will be modified, so the build may becomes very slow. - Another way is to run
git rebase master my-feature
. When running this command, git will apply each commit frommy-feature
on to the currentmaster
branch. Finally we will rebase and check out to themy-feature
branch. Changes in the workspace only contains the commits frommy-feature
branch, so the incremental build will be fast.
1 | Before |
1 | After |
Reference: